Listing all child controls

  • Thread starter Thread starter Soren-a
  • Start date Start date
S

Soren-a

Hi

I am trying to get a list/Array with the name/type of all the controls
(buttons, Label, Panels ect.) that has a specific Panel as Parent.

Does anyone know how to do this?

Regards
Søren Augustesen
 
The Control base class has a property Controls which as a collection of all
the child controls below it, you can access individual controls by their
index in the collection, or use a foreach loop to iterate through them e.g.

foreach(Control c in myPanel.Controls)
{
}

You'll probably want to call GetType on each control to determine exactly
what type of control it is, and then you can cast to that type to access
it's specific properties (other than those exposed by Control).

Peter
 
Back
Top