How can I get the active screen dimensions? How can I get the active screen dimensions? wpf wpf

How can I get the active screen dimensions?


Screen.FromControl, Screen.FromPoint and Screen.FromRectangle should help you with this. For example in WinForms it would be:

class MyForm : Form{  public Rectangle GetScreen()  {    return Screen.FromControl(this).Bounds;  }}

I don't know of an equivalent call for WPF. Therefore, you need to do something like this extension method.

static class ExtensionsForWPF{  public static System.Windows.Forms.Screen GetScreen(this Window window)  {    return System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(window).Handle);  }}


You can use this to get desktop workspace bounds of the primary screen:

System.Windows.SystemParameters.WorkArea

This is also useful for getting just the size of the primary screen:

System.Windows.SystemParameters.PrimaryScreenWidthSystem.Windows.SystemParameters.PrimaryScreenHeight


Also you may need:

to get the combined size of all monitors and not one in particular.