0

私は 16*64 の行列を描画したいと思います。それぞれに以下が含まれています。

Microsoft.VisualBasic.PowerPacks.OvalShape.

私はこれを使用しました:

List<Microsoft.VisualBasic.PowerPacks.OvalShape> ovalShape = 
    new List<Microsoft.VisualBasic.PowerPacks.OvalShape>();

for (int i = 0; i < 16; i++)
{
    for (int j = 0; j < 64; j++)
    {
        OvalShape ovl = new OvalShape();
        ovl.Width = 20;
        ovl.Height = 20;
        ovl.FillStyle = FillStyle.Solid;
        ovl.FillColor = Color.Green;

        ovalShape.Add(ovl);
    }
}

ウィンドウに表示するにはどうすればよいですか?

4

3 に答える 3

2

形状ごとに個別のコンテナを作成する必要はありません。また、図形の追加のコンテナリストをスキップすることもできます。したがって、この非常にコンパクトなコードを使用できます。

        var ovalShapes = new Microsoft.VisualBasic.PowerPacks.ShapeContainer()
        {
            Dock = DockStyle.Fill,
            Margin = new Padding(0),
            Padding = new Padding(0),
        };
        for (int i = 0; i < 16; i++)
            for (int j = 0; j < 64; j++)
                ovalShapes.Shapes.Add(
                    new Microsoft.VisualBasic.PowerPacks.OvalShape()
                    {
                        Width = 20,
                        Height = 20,
                        FillStyle = Microsoft.VisualBasic.PowerPacks.FillStyle.Solid,
                        FillColor = Color.Green,
                        Location = new Point(20 * i, 20 * j),
                    });
        this.Controls.Add(ovalShapes);
于 2012-09-24T09:09:35.027 に答える
1

MSDNから:

OvalShape コントロールは、フォームまたはコンテナー コントロールに直接表示できません。ShapeContainer オブジェクトに含まれている必要があります。OvalShape を初期化した後、その Parent プロパティを既存の ShapeContainer または ShapeContainer の新しいインスタンスに設定する必要があります。

Location を設定し、フォームにコントロールを追加してみてください:

        List<Microsoft.VisualBasic.PowerPacks.OvalShape> ovalShape = new List<Microsoft.VisualBasic.PowerPacks.OvalShape>();

        for (int i = 0; i < 16; i++)
        {
            for (int j = 0; j < 64; j++)
            {
                OvalShape ovl = new OvalShape();
                ovl.Width = 20;
                ovl.Height = 20;
                ovl.FillStyle = FillStyle.Solid;
                ovl.FillColor = Color.Green;

                ovl.Location = new Point(ovl.Width*i, ovl.Height*j);

                ovalShape.Add(ovl);
            }
        }

        foreach(OvalShape os in ovalShape)
        {
              Microsoft.VisualBasic.PowerPacks.ShapeContainer shapeContainer = new Microsoft.VisualBasic.PowerPacks.ShapeContainer();
              Control c = new Control();
              shapeContainer.Parent = c;
              os.Parent = shapeContainer;
              myForm.Controls.Add(c);              
        }
于 2012-03-28T20:48:48.623 に答える
0

まず単純化する

int totalCount = 1024; //16*64
const int shapeWidth  =20;
const int shapeHeight = 20;

for (int j = 0; j < totalCount; j++)
{
   OvalShape ovl = new OvalShape();
   ovl.Width = shapeWidth;
   ovl.Height = shapeHeight;
   ovl.FillStyle = FillStyle.Solid;
   ovl.FillColor = Color.Green;

   ovalShape.Add(ovl);
}

描画領域を選択したら、行ごとにどのくらいの図形を配置するかを決定します。したがって、仮想コード次のようになります。

int shapesPerRowCount = 5;
int yPos = 0;

for(int i=0;i<ovalShape.Count;i++)
{
  if(i % shapesPerRowCount  == 0) //reach end of the row, so offset Y position by Height
     yPos += shapeHeight; 

  int xPos = i*shapeWidth;
  DrawShapeAtPos(ovalShape[i], xPos, yPos); //some special function that draws the shape
}

非常に一般的なコードですが、アイデアを提供するだけです。

探しているものではない場合は、明確にしてください。

于 2012-03-28T20:55:58.707 に答える