ASP tutorial. NET build control automatically gets the name value of the control
Convenient with the Tag property of the control
private void Message (Object Sender,eventargs e)
{
PictureBox pic = sender as PictureBox;
String Lblname= ((label) pic.tag). Name;
MessageBox.Show (Lblname);
}
When the control is dynamically generated, specify name, and then locate it:
foreach (Control ct in form1.controls)
{
C # only traverses the child controls of the form and does not traverse the sun control
When a control on a form has child controls, you need to iterate recursively to list all the controls on the form
if (ct.name== "")
{
}
}
}
Instance
PictureBox p = new PictureBox ();
P.name = "P" + i.tostring ();
P.sizemode = System.windows.forms.pictureboxsizemode.stretchimage;
P.imagelocation = @ "D:www.111cn.nethome4.png";
P.size = New System.Drawing.Size (60, 60);
P.location = New System.Drawing.Point (5 * i-60, 50);
P.cursor = System.windows.forms.cursors.hand;
P.doubleclick + + new EventHandler (message);
P.mousemove + = new System.windows.forms.mouseeventhandler (this.mouseo tutorial ver);
P.mouseleave + = new System.EventHandler (this.mouseo tutorial UT);
P.contextmenustrip = CONTEXTMENUSTRIP1;
This.sp_l_r.panel2.controls.add (P);
Label La = new label ();
La.name = "La" + i.tostring ();
La.text = "0000";
La.location = New System.Drawing.Point (50, 120);
This.sp_l_r.panel2.controls.add (LA);