c# - Visual Basic 电源包

标签 c# visual-studio-2010 windows-forms-designer

我正在使用 Visual Studio 2010,我想在 Windows 窗体 C# 应用程序中从 VB PowerPack 创建多个 OvalShapes,但我不想将它们从工具箱中拖动,而是想手动创建它们,问题是如果我将它们声明为变量,它们将不会出现在表单中,我怎样才能让它们出现,谢谢...

代码:

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... 
    } 
   } 
 }

最佳答案

你想要的是这样的:

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
        }
    }
}

关于c# - Visual Basic 电源包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8279036/

相关文章:

c# - 如何在 Azure 广告身份验证中停止注销询问您要注销哪个帐户?

c# - 如何跳过字符串中的 `\r\n `

c# - T4 模板错误 : loading the include file ef. utility.cs.ttinclude 返回了 null 或空字符串

visual-studio-2010 - VS2010 RDLC C#。如何将 LocalReport 对象设置为 ReportViewer?

c# - 无法在 Windows 桌面窗体 .NET Core 应用程序中打开窗体 [设计] View

c# - 如何在 C# Windows 窗体应用程序中的列表框中显示结构的内容

c# - 如何对从 Task.ContinueWith 衍生出来的方法进行单元测试?

c# - 使用枚举中的位置顺序创建枚举列表,而不是值

c++ - 跨平台 64 位类型

c# - 用户控件的结构体属性的代码生成