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
 

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