MessageBox Centering

C

Chuck

Is there anyway to get a MessageBox to center in the parent form or in
the middle of a MDI parent? The .NET standard MessageBox is centered
on the screen area, not on the application.

Specifing the owner doesn't seem to work reliably in MDI applications
public static DialogResult Show(
IWin32Window owner,
string text
);

In 1.1 you had to use a WH_CALLWNDPROC hook and look for a
WM_INITDIALOG or write your own MessageBox routine

I hate it when you do MessageBox.Show() and the messagebox pops up in
the second display or in someother non-intutive location.

thanks,
 
J

Jeffrey Tan[MSFT]

Hi Chuck,

Thanks for your post.

MessageBox.Show method internally uses MessageBox win32 API to do the
actual work. This API does not provide any interface to change the message
box location. So MessageBox.Show did not provide any interface to control
its location

Hope it helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
C

Cerebrus

Hi,

MessageBoxes are centered on screen by default. If you find that
un-intuitive, you might try to center the parent form on screen, so
that the Messagebox now shows as centered on the parent form as well.

If that isn't possible, try a custom implementation of a Messagebox.

HTH,

Regards,

Cerebrus.
 
C

Chuck

Sometimes the users move the parent form, from one display to another.
I'd rather not recenter the parent when I have to display a message
box or modal form. I will go back to com interop.
 
B

Brian P. Hammer

Don't think it's possible. I built my own messagebox that I could control
and use it in several different projects.

Brian
 
J

Jeffrey Tan[MSFT]

Hi Chuck,

Thanks for your feedback.

As I stated in the original post, .Net MessageBox.Show() method only
encapsulates the Win32 MessageBox() API. So this issue is not due to the
limitation of .Net, but Win32 API.

Yes, because message box is also a win32 window, we can use all the win32
UI technology to manipulate it.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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