tags:

views:

1416

answers:

2

I have a 700w x 300h WPF applciation and can drag it anywhere on my large screen.

When my application executes:

MessageBox.Show("Sorry, this function is not yet implemented.");

the mesage box appears in the middle of my screen, which may or may not even be near the application itself.

How can I get my MessageBox to appear in the middle of my application instead?

A: 

The first parameter can be Window Owner, so if you set it to application window, the message box will be shown in front of it.

MessageBox.Show(this, "Can't login with given names.", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel);

EDIT: This will put the message box in the front of the application window by the means of the Z-order, but not necessary between the borders of the application window.

Nenad
Right, the message box is "in front of my application" in terms of zindex but my small application may be in the upper right-hand corner of the screen the message box pops up in the middle of my screen, which gives the effect that it has nothing to do with my application. Howto put it within my app?
Edward Tanguay
what I want to do is center the message box within the borders of my application window, e.g. with something like: MessageBox(this.Width/2, this.Height/2, "Not implemented funtion.")
Edward Tanguay
+1  A: 

If your app has several windows, you might want to use Application.Current.MainWindow:

MessageBox.Show(Application.Current.MainWindow, "Can't login with given names.", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel);