How to determine the screen width/height using C#

Shamim Hafiz picture Shamim Hafiz · Jun 8, 2011 · Viewed 67.7k times · Source

I want to set the width & height of a Window dynamically based on the user screens maximum width/height. How can I determine this programmatically?

Answer

H.B. picture H.B. · Jun 8, 2011

For the primary screen:

System.Windows.SystemParameters.PrimaryScreenWidth
System.Windows.SystemParameters.PrimaryScreenHeight

(Note that there are also some other primary screen related properties which depend on various factors, Full* & Maximised*)

Virtual screen:

SystemParameters.VirtualScreenWidth
SystemParameters.VirtualScreenHeight