1

The Line shape is one of tools of VisualBasic power pack 1.0 (in vs2010) ,

How can I define a label property and set value to it when I add it to a container control:

My code is below and ( at Design time ) need

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

///--------- call in master form :

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);

result: The line is drawn on the form but label isn't visible

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
Harry Sarshogh
  • 2,137
  • 3
  • 25
  • 48

1 Answers1

3

Give the label a size and location, and add it to the control too. Something like:

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

Take a looks at any Designer.cs file for a form you've created, and you'll see how the IDE does it.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
Grant Winney
  • 65,241
  • 13
  • 115
  • 165