7

In a PC with multiple monitors, say you run your application which have have a second Window/Dialog other than the main window (such as Options) that you want it to open in the same screen/monitor as your MainWindow. How to force this behavior?

You basically want to stop the scenario that your MainWindow is on one monitor and when you bring up the "Options" page, it shows on a different screen/monitor.

Mehrad
  • 4,093
  • 4
  • 43
  • 61
  • It may just be too late in the day, but I don't understand your question. Could you try rephrasing it or posting a sketch of what you're trying to do? – goobering Mar 13 '15 at 01:54
  • 3
    @goobering: On a multi-monitor setup, sometimes a dialog will show up on a different monitor from its parent window. This is not desirable. – Nathan Tuggy Mar 13 '15 at 01:56

3 Answers3

8

Have you looked at the WindowStartupLocation property for Window?

CenterScreen places the Window in the center of the screen containing the cursor, which should normally be fine. For example, if a user clicks a button on your Window and a dialog opens, the cursor will still be over the button and thus the dialog will show up in the center of the same Window.

CenterOwner places the Dialog in the center of the Window specified as it's owner. Declare the new Window similar to this:

MyDialog d = new MyDialog { Owner = parentWindow };
d.ShowDialog();
learningcs
  • 1,856
  • 16
  • 25
  • Not sure where did you get the **Centre** interpretation from my question but in general setting the owner did the trick for what I asked for. `optionsView.Owner = Application.Current.MainWindow;`. and it doesn't use the `System.Windows.Forms` cuz the dialog always follows it's owner in whichever screen it is. :) – Mehrad Mar 13 '15 at 02:26
  • 1
    Yeah, I think I got sidetracked and forgot what you were actually asking... Glad to help! – learningcs Mar 13 '15 at 02:30
0

I'd like to add to this the fact that if you start the second dialog maximized, it will default to the main screen. As a workaround, I set the maximize flag in the OnLoad method.

CaptainCodeman
  • 1,951
  • 2
  • 20
  • 33
0

If you want the dialog to open on the same output screen as the parent form you need to set the StartPosition

ChildDialog cd = new ChildDialog() { StartPosition = FormStartPosition.CenterParent };
cd.ShowDialog();
Jack
  • 526
  • 3
  • 10
  • 30