Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the screen width/height using C#

Tags:

c#

css

screen

wpf

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?

like image 330
Shamim Hafiz - MSFT Avatar asked Jun 08 '11 11:06

Shamim Hafiz - MSFT


People also ask

How do I find my screen width and height?

The size of a 16:9 screen depends on how long the screen's diagonal is, as 16:9 is merely the ratio of the screen's width to its height. If you have the screens diagonal, you can multiply that measurement by 0.872 to get the screen's width. You can also multiply the diagonal by 0.49 to get the screen's height.

How do you measure screen width?

The screen width is equal to the aspect ratio width ARw times the screen diagonal divided by the square root of the aspect ratio width ARw squared plus the aspect ratio height ARh squared.

What is screen width and height?

It is usually quoted as width × height, with the units in pixels: for example, 1024 × 768 means the width is 1024 pixels and the height is 768 pixels. This example would normally be spoken as "ten twenty-four by seven sixty-eight" or "ten twenty-four by seven six eight".


1 Answers

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 
like image 175
H.B. Avatar answered Oct 13 '22 01:10

H.B.