Is there a collection for non-visual components on a win form?

G

Guest

Hi,
I'm writing a component that iterates through the ParentForm.Controls
collection looking for components of a certain type. However, some of the
components I need to find are of a non-visual nature and aren't present in
the collection. Is there another collection I need to look in. I've tried the
form's components collection, but its empty.
ie...

for(int x = 0; x<this.ParentForm.Controls.Count; x+=1){
MessageBox.Show(this.ParentForm.Controls[x].Name);
MessageBox.Show(this.ParentForm.Components[x].Name);

}


Thanks
 
R

Rodger Constandse

Hi Rob,

The VS.NET designer creates a private data member of type IContainer called
"components" that it uses to keep track of all these non-visual components in
the form. It uses this variable in the generated Dispose method to dispose all
these non-visual components.

This "components" object (if one is created by the designer, could be null if
there are no components in the form) has a Components property that you can use
to cycle through the components in the Form.

You can provide you own property in the form to access this variable from outside.

I'm not sure why the Components property of the form itself was not used for this.

Best regards,

Rodger

Time Management Guide - Make better use of your time
<http://www.TimeThoughts.com/timemanagement.htm>
 

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

Top