0

Throughout all my applications, if I wish to size a window according to the current monitor resolution I use the following:

     System.Drawing.Rectangle workingArea = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(App.Current.MainWindow).Handle).WorkingArea;

However, I have one client, who uses multiple monitors, where this is just not working. The resized window is spanning across to a second monitor. Only this one client. I've tested this using multiple monitors and it works fine.

Can anyone please suggest a better/alternative method?

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Muckers Mate
  • 399
  • 8
  • 23
  • 3
    Can't you simply maximize the window? – mm8 Jan 23 '18 at 10:18
  • It's a dialog, using MUI. Dialogs cannot be "maximised". I set the form dimensions at runtime , as shown. Why on all the dozens of PC's which have multiple monitors attached, does it mess up on this one? I've seen a screenshot, and the window is spanning across to the second monitor – Muckers Mate Jan 23 '18 at 11:32
  • duplicate of [this one](https://stackoverflow.com/questions/1927540/how-to-get-the-size-of-the-current-screen-in-wpf)? – default Jan 23 '18 at 14:45

2 Answers2

0

For any FrameworkElement you can get it's rendered size (Height and Width) by using this.

FrameworkElement.ActualWidth;
FrameworkElement.ActualHeight;

so in this case you can use it for your window.

Lion King
  • 495
  • 5
  • 14
  • Why on all the dozens of PC's which have multiple monitors attached, does it mess up on this one? I've seen a screenshot, and the window is spanning across to the second monitor. – Muckers Mate Jan 23 '18 at 11:33
0

You need to use Windows Forms' class System.Windows.Forms.Screen. It allows for screen enumeration, and to get your WPF window's screen, use this Screen.FromHandle(new WindowInteropHelper(this).Handle) snippet. There is, however, an issue with hi-res screens - you need to convert WPF's 96 dpi to whatever pixel density your monitor has.

Alex Seleznyov
  • 905
  • 6
  • 18