I've tried several ways to list all the non-visual components of a form, such as: OpenDialog
, ImageList
, TableAdapters
, and so on. but without success.
To find the controls on the screen, I got a Foreach
in the Controls from the screen, but for those 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 non-visual component listing process?