开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜