How to get all control names and atributes from a form at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to Get all controls names, some properties, etc... from a form at runtime.
Anyone knows how can i enumerate all controls from a form?

Thanks for your help,
 
Hi,

this is in the server or in the client?

If in the server you can use the Controls collection, but be aware, you need
to do a deep search of it, as each control inside this collection can have
controls itself. !!!

something like this:

void iteratecontrol( ControlCollection controls)
{
foreach( Control current in controls)
{
UseCurrentControl( current );
//Iterate in the children
iteratecontrol( current.Controls);
}
}


Hope this help,
 
in the form's class

foreach(Control ctl in this.Controls)
{
System.Diagnostics.Debug.WriteLine( ctl.Name);
...
}

Or, to get everything nested in a GroupBox called OptionsGroup,
foreach(Control ctl in OptionsGroup.Controls)
{
System.Diagnostics.Debug.WriteLine( ctl.Name);
...
}
 
Back
Top