How to make a dialog(view) open up on the same monitor as the main window

前端 未结 2 1235
野趣味
野趣味 2021-01-19 00:31

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 00:50

    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();
    

提交回复
热议问题