Home All Groups Group Topic Archive Search About

Invoke on Dialog not yet shown

Author
17 Mar 2005 5:56 PM
andrew.bell.ia
Hi,

I want to call Invoke() on a dialog that has not yet been made visible
with "Show()".  When I make the Invoke() call, I get an exception like:

System.InvalidOperationException: Cannot call Invoke or BeginInvoke on
a control until the window handle has been created.

   at System.Windows.Forms.Control.MarshaledInvoke(Control caller,
             Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method,
             Object[] args)
   at NRI.Scan.DoqRequest.getImage()
             in c:\acbell\si\NriScan\DoqRequest.cs:line 147

How can I give the dialog a handle without making it visible?  I tried
calling CreateControl() on the dialog to no avail.  If the dialog is
made visible, everything works fine, but of course, this isn't what I
want :)

Thanks for any help,

-- Andrew Bell
andrew.bell***@gmail.com

Author
17 Mar 2005 6:05 PM
DotNet Coder
Hi Andrew,

Mark the dialog's Visible property as false. Then create it, you would have
a handle to the dialog that you could call invoke on it with the dialog
showing.

HTH,
~d

<andrew.bell***@gmail.com> wrote in message
Show quoteHide quote
news:1111082219.173724.233440@z14g2000cwz.googlegroups.com...
> Hi,
>
> I want to call Invoke() on a dialog that has not yet been made visible
> with "Show()".  When I make the Invoke() call, I get an exception like:
>
> System.InvalidOperationException: Cannot call Invoke or BeginInvoke on
> a control until the window handle has been created.
>
>   at System.Windows.Forms.Control.MarshaledInvoke(Control caller,
>             Delegate method, Object[] args, Boolean synchronous)
>   at System.Windows.Forms.Control.Invoke(Delegate method,
>             Object[] args)
>   at NRI.Scan.DoqRequest.getImage()
>             in c:\acbell\si\NriScan\DoqRequest.cs:line 147
>
> How can I give the dialog a handle without making it visible?  I tried
> calling CreateControl() on the dialog to no avail.  If the dialog is
> made visible, everything works fine, but of course, this isn't what I
> want :)
>
> Thanks for any help,
>
> -- Andrew Bell
> andrew.bell***@gmail.com
>
Are all your drivers up to date? click for free checkup

Author
28 Mar 2005 2:49 PM
andrew.bell.ia
This doesn't work.  As the documentation says, calling "Show" will make
the dialog visible, which isn't what is wanted.

For anyone else having the same problem, I found the solution in
another newsgroup.  Accessing the "Handle" property seems to cause the
handle to get created:

form.Handle.toInt32();

does the trick.

Bookmark and Share