[RESOLVED] [2005] Loading a form's instance+handle+not visible
Just wondering...
Is there a way to load an instance of a form, and then call Invoke on it? If I don't show it, it tells me it doesn't have a handle, so Invoke and BeginInvoke can't be called. I found a workaround of accessing the handle (I guess it forces one to be assigned) by just putting fRead.Handle.ToInt32() in the middle of the code, but I'm wondering if there's a smarter way to do it...
Thanks :)
Re: [2005] Loading a form's instance+handle+not visible
From the documentation from the Control.CreateControl method:
Quote:
The CreateControl method forces a handle to be created for the control and its child controls. This method is used when you need a handle immediately for manipulation of the control or its children; simply calling a control's constructor does not create the Handle.
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.
CreateControl will not work because the form is not visible. CreateHandle is Protected so can only be called within the form. If this functionality should be part of the form itself then you could call CreateHandle at the end of the constructor or else provide a public method that calls CreatHandle internally. Otherwise your accessing the Handle property goes along with the advice in the documentation.
Re: [RESOLVED] [2005] Loading a form's instance+handle+not visible