1. Use lable as an example:
Place a widget in form to keep the widget centered during startup and dynamic window change.
Int gleft = This. width/2-lable1.width/2; // This indicates form
Int gtop = This. Height/2-lable1.height/2;
Lable1.location = new point (gleft, gtop );
2. dynamically create and locate or delete controls
1. Use lable as an example to create a control:
Label LBL = new label ();
LBL. Name = "lblnum" + m;
LBL. autosize = true;
LBL. backcolor = system. Drawing. color. transparent;
LBL. font = new system. drawing. font ("", 36f, system. drawing. fontstyle. bold, system. drawing. graphicsunit. point, (bytes) (134 )));
LBL. forecolor = system. Drawing. color. White;
LBL. Location = new system. Drawing. Point (lable1.location. X-150, 29 );
LBL. textalign = system. Drawing. contentalignment. topcenter;
LBL. Anchor = system. Windows. Forms. anchorstyles. Top;
// This. Controls. Add (LBL); add controls to the form
This. groupbox2.controls. Add (LBL );//Add controls to groupbox2
2. Use lable as an example to delete the control:
If (this. groupbox2.controls. Containskey("Lable2") = true)
{
This. groupbox2.controls.Removebykey("Lable2 ");
}
3. Locate the control and assign values to it.
Control [] control = This. Controls. Find ("lable1", true );
If (control. Length = 1 & Control [0] Is label)
{
(Control [0] As label). Text = "hello ";
}