FINDING CONTROL

  • Thread starter Thread starter Jose Fernandez
  • Start date Start date
J

Jose Fernandez

Hello
I have a winforms with 5 controls.
2 of them, with the Name by default, the rest, I changed the names.
When I perform this

foreach(Control c in Controls)

it only finds the 2 controls with their default names. The other 3 are not
listed.

How can I find these controls???
Thanks in advance
 
Well, if the control can contain other controls (such as a panel or
groupbox) you have to look among those control:

Control FindControl(Control ctrl, string name)
{
foreach(Control c in ctrl.Controls)
{
if (c.Name == name)
return c;

if (c.Control.Count > 0)
{
Control cc = FindControl(c, name);
if (cc != null)
return cc;
}
}
return null;
}

}
 
Back
Top