4
I have tried several means to list all the non-visual components of a form, such as: OpenDialog
, ImageList
, TableAdapters
and etc. but without success.
To find the controls on the screen, I managed with a Foreach
us Controls of the screen, but for these non-visual components, I found nothing.
My current code:
private IEnumerable<Component> EnumerateComponents()
{
return from field in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
where typeof (Component).IsAssignableFrom(field.FieldType)
let component = (Component) field.GetValue(this)
where component != null
select component;
}
Any idea how to do this process of listing non-visual components?
You got that in that answer, right? http://stackoverflow.com/questions/17171914/find-components-on-a-windows-form-c-sharp-not-controls Does it not work? I just saw that you posted on Soen also: http://stackoverflow.com/questions/27026373/find-components-non-visual-c-sharp If you find a good answer there, put it here for us.
– Maniero
Absolutely @bigown. Finding an answer, I put it this way.
– danielvillage
@danielvillage just performed a test with the code you posted, here appeared the Imagelist and Openfiledialog I put to test.
– mateusalxd
@Mateusalexandre, this code here is more complete. It’s what I wanted. Take a look: Return this.Gettype(). Getfields(Bindingflags.Instance | Bindingflags.Public | Bindingflags.Nonpublic) . Where(f => typeof(Component).Isassignablefrom(f.Fieldtype)) . Where(f => !typeof(Control).Isassignablefrom(f.Fieldtype)) . Select(f => f.Getvalue(this)) . Oftype<Component>();
– danielvillage