1

Line shape是VisualBasic power pack 1.0(在vs2010中)的工具之一,

当我将标签属性添加到容器控件时,如何定义标签属性并为其设置值:

我的代码在下面并且(在设计时)需要

public class MyLine:Microsoft.VisualBasic.PowerPacks.LineShape
{
    public Label label ;
    public MyLine()
    {
    }       
    public MyLine(ShapeContainer container)
        : base(container)
    {
        label = new Label() { Text = "Ali_Sarshogh" };
    }
}

///--------- 以主表单调用:

private Microsoft.VisualBasic.PowerPacks.ShapeContainer shapeContainer1;

 //--- in Button1_Click() i want to draw it :
  MyLine lineShape1 = new MyLine(shapeContainer1);
        lineShape1.Name = "lineShape1";
        lineShape1.X1 = 25;
        lineShape1.X2 = 160;
        lineShape1.Y1 = 18;
        lineShape1.Y2 = 17;
 this.shapeContainer1.Shapes.Add(lineShape1);

结果:在表单上绘制了线条,但标签不可见

4

1 回答 1

3

给标签一个大小和位置,并将它也添加到控件中。就像是:

public MyLine(ShapeContainer container) : base(container)
{
    label = new Label() { Text = "Ali_Sarshogh" };
    label.Location = new Point(0, 0);
    label.Size = new Size(100, 14);
    this.Controls.Add(label);
}

Designer.cs查看您创建的表单的任何文件,您将了解 IDE 是如何执行此操作的。

于 2013-03-16T07:08:09.357 回答