Visual Basic Power Packs

本文关键字:Packs Power Basic Visual | 更新日期: 2023-09-27 18:15:43

我使用的是visual studio 2010,我想在Windows窗体c#应用程序中从VB PowerPacks创建几个ovalshape,但我不想从工具箱中拖动它们,而是我想手动创建它们,问题是,如果我将它们声明为变量,它们不会出现在窗体中,我怎么能使它们出现,谢谢…

代码:

using System; 
using System.Collections.Generic; 
System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using Microsoft.VisualBasic.PowerPacks; 
using System.Windows.Forms; 
namespace VB_PP 
{ 
  public partial class Form1 : Form 
   { 
    OvalShape[] OS_Arr; 
    public Form1() 
    { 
     InitializeComponent(); 
     OS_Arr = new OvalShape[15]; //I will do some coding on the array of those OvalShapes,like move them with a Timer... 
    } 
   } 
 }

Visual Basic Power Packs

你想要的是这样的:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.PowerPacks;
namespace VBPowerPack
{
    public partial class Form1 : Form
    {
        private ShapeContainer shapeContainer;  //Container that you're gonna place into your form
        private Shape[] shapes;                 //Contains all the shapes you wanna display
        public Form1()
        {
            InitializeComponent();
            shapes = new Shape[5];              //Let's say we want 5 different shapes
            int posY = 0;
            for (int i = 0; i < 5; i++)
            {
                OvalShape ovalShape = new OvalShape();      //Create the shape you want with it's properties
                ovalShape.Location = new Point(50, posY);
                ovalShape.Size = new Size(75, 25);
                shapes[i] = ovalShape;                      //Add the shape to the array
                posY += 30; 
            }
            shapeContainer = new ShapeContainer();
            shapeContainer.Shapes.AddRange(shapes);         //Add the array of shapes to the ShapeContainer
            this.Controls.Add(shapeContainer);              //Add the ShapeContainer to your form
        }
    }
}