Messagebox location

G

Guest

I hope this is one of those simple questions that for some reason or another,
I'm just missing the obvious.

Using VB.NET 2003

I want my messagebox to display centered on the parrent form instead of the
desktop. The docs say to use

messagebox.show(owner as IWin32Window, ...

How do I obtain "owner" and successfully pass it as a parameter. Everything
I've tried either generates and error or simply results in the messagebox
centered on the desktop like always.

Thanks for any help
 
S

Scott M.

Owner is the name of the form instance that the messagebox is supposed to
center itself on.
 
H

Herfried K. Wagner [MVP]

Scott M. said:
Owner is the name of the form instance that the messagebox is supposed to
center itself on.

That's not true. Messageboxes are centered on the screen, not over the form
by default, even if an owner window is set.
 
H

Herfried K. Wagner [MVP]

Doug Robertson said:
I want my messagebox to display centered on the parrent form instead of
the
desktop. The docs say to use

messagebox.show(owner as IWin32Window, ...

How do I obtain "owner" and successfully pass it as a parameter.
Everything
I've tried either generates and error or simply results in the messagebox
centered on the desktop like always.

You will have to use a Win32 dialog hook to catch creation of the message
box and then set its position accordingly. Sample in VB6:

DialogPosition
<URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>
 
S

Scott M.

While it may be true that message boxes center on the screen, it is also
true that "owner" is "The System.Windows.Forms.IWin32Window the message box
will display in front of." This comes directly from the VS.NET help.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsformsmessageboxclassshowtopic12.htm
 

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