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

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

Post by Um9i » Fri, 24 Jun 2005 07:12:01



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
--
Rob G
 
 
 

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

Post by Herfried K » Fri, 24 Jun 2005 07:28:59

"Rob" < XXXX@XXXXX.COM > schrieb:

See:

<URL: http://www.yqcomputer.com/ %24rM4.13835730%40news4.tin.it>

--
M S Herfried K. Wagner
M V P <URL: http://www.yqcomputer.com/ ;
V B <URL: http://www.yqcomputer.com/ ;

 
 
 

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

Post by Um9i » Sun, 26 Jun 2005 05:23:05

Very nice Herfried. Thanks.
--
Rob G
 
 
 

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

Post by Rodger Con » Sun, 26 Jun 2005 06:17:15

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.yqcomputer.com/ ;