Reflecting form controls in inherited user controls
C#
1
Posts
1
Posters
0
Views
1
Watching
-
I want to enumerate all form controls on a user control that inherits from another user control (which also has controls on it). Here's some sample code. UserC in this sample is the user control which inherits from the base class user control.
int BindingFlags = Reflection.BindingFlags.Instance | Reflection.BindingFlags.Public | Reflection.BindingFlags.NonPublic;
foreach (System.Reflection.FieldInfo fi in UserC.GetType.GetFields(BindingFlags)) {
object obj = fi.GetValue(UserC);
if (obj != null)
{
try {
obj.Name();
}
catch (Exception ex) {
}
}
}This will list all the form controls on the UserC class designer but not the base class it inherits from. You can see them all when debugging. What gives?