Why do hidden controls on my .Net application fail to match within OpenSpan?

Programs Affected: All OpenSpan versions.


Issue

Controls I have added to my .Net application are hidden, but are not matched in my OpenSpan solution.

Resolution

To make a hidden control within a .Net application accessible to OpenSpan, you must call the CreateHandle method of the control. CreateHandle is a protected method so you will need to invoke it using reflection. The following code invokes CreateHandle using reflection:

// Must specify Instance and NonPublic MethodInfo info = typeof(Control).GetMethod( "CreateHandle", BindingFlags.Instance | BindingFlags.NonPublic); info.Invoke(txtCreateHandle, new object[] {});

The public method, CreateControl, also states that it will force the creation of a window. However, CreateControl will not work if a control is not visible. The remarks sections states:

CreateControl does not create a control handle if the control's Visible property is false. You can either call the CreateHandle method or access the Handle property to create the control's handle regardless of the control's visibility, but in this case, no window handles are created for the control's children.

Attached is a sample executable that demonstrates this behavior. If you examine the form in Spy++ you will notice that no EDIT windows are created. If you click “Make Visible”, you will notice that one EDIT control is now created. This demonstrates that .NET waits until a control is visible to create the underlying EDIT window. If you click “Create Handle”, you will notice that one additional EDIT control is now created.


Attachments Attachments

CreateHandleExampleSolution.zip
Article is in the following categories:
KB » Studio» Troubleshooting

KB » Studio» Browse By Project Item» Windows Application

KB » Get Started» Recent Content


Leave A Comment

or close

Email This Article

or close