开发者

How to get the actual control object from FieldInfo in .NET Reflection?

开发者 https://www.devze.com 2023-03-06 06:03 出处:网络
I need to get the \"control\" object from the fieldInfo object in C# using reflection. Control mainControl = Control.FromHandle(a_hWnd);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消