1
votes

I'm trying to position a WPF dialog window on the top left corner of the current screen. However, I do not know how to get those coordinates for any other screen than the primary one. For the primary screen Top and Left would be 0. However, for any other screen I would need to know the offset. I could have a second or even third screen. To make things more complicated: Those other screens could (in theory) be positioned to the left, top or below the primary screen.

I did some research but was not able to find a solution. Could someone please point me to the right direction?

2
Did you try this?mm8
mm8's suggestion pointed me to the solution.Ralf

2 Answers

0
votes

Try setting values to Window.Left and Window.Top:

window.Left = 0;
window.Top = 0-window.Height;

window.ShowDialog();
0
votes

As it turns out, I just did not see the neccessary properties: Each Screen object has its own Top and Left property within its WorkingArea.

This works for me:

var topLeftCornerOfMainWindow = new System.Drawing.Point((int)System.Windows.Application.Current.MainWindow.Left, (int)System.Windows.Application.Current.MainWindow.Top);
var currentScreen = Screen.FromPoint(topLeftCornerOfMainWindow);

this.Top = currentScreen.WorkingArea.Top;
this.Left = currentScreen.WorkingArea.Left;
this.Width = currentScreen.WorkingArea.Width;
this.Height = currentScreen.WorkingArea.Height;