Invoke on Dialog not yet shown

A

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
(e-mail address removed)
 
D

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
 
A

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top