Hello Andrew,
>I have a need to cycle through the compoents on the form in my program at
>run time to check for the existence of certain components.
The most reliable way to do this would involve using Reflection. For
instance, this snippet outputs the name of each Component that is stored
in a private field in the Form derived class (which is true at least for
all the components the VS designer handles):
Type formType = this.GetType( );
FieldInfo[] fields = formType.GetFields( BindingFlags.Instance |
BindingFlags.NonPublic);
foreach (FieldInfo field in fields) {
if (typeof(Component).IsAssignableFrom(field.FieldType))
Debug.WriteLine(field.Name);
}
For your purpose I guess you'd have to modify this a bit - for example,
use field.GetValue() to retrieve a reference to the actual component
instance or something like that.
Oliver Sturm
--
http://www.sturmnet.org/blog