I need to get the "control" object from the fieldInfo object in C# using reflection.
Control mainControl = Control.FromHandle(a_hWnd);
object oMainControlObject = mainControl;
FieldInfo[] fi开发者_如何转开发eldInfos = oMainControlObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
For each fieldInfo in the fieldInfos array, I need to get the corresponding control object.
My Attempts:
Control oControl = Control.FromHandle(fieldInfo.FieldHandle.Value);
Control oControl = (Control)FieldInfo.GetValue(mainControl)
The first one returns NULL and the second one is not allowing me to typecast the above statement to control.
Regards,
Usman
It sounds like you want to recursively iterate through the Controls
collection.
精彩评论