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,
 
System.Windows.Forms.Control.ControlCollection = Control.Controls
 
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);
...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top