How to Get Screen Size in C#

Muhammad Maisam Abbas Feb 16, 2024
  1. Get Screen Size of the Primary Screen With the SystemParameters Class in C#
  2. Get Screen Size of All Screens With the SystemParameters Class in C#
How to Get Screen Size in C#

This tutorial will discuss the methods for finding the dimensions of a screen C#.

Get Screen Size of the Primary Screen With the SystemParameters Class in C#

The size of the screen refers to the resolution of the screen in this scenario. The screen’s resolution is the product of the number of pixels from left to the right and the number of pixels from top to bottom. The SystemParameters class contains properties that can be used to query the system settings information in C#. The SystemParameters.FullPrimaryScreenHeight property gets the full height of the primary monitor. The height of the screen is the number of pixels from the top to bottom of the screen. The SystemParameters.FullPrimaryScreenWidth property gets the full width of the primary monitor. The width of the screen is the number of pixels from left to right of the screen. We can use both these properties to get the size or the resolution of the primary monitor. The following code example shows us how we can find the primary monitor’s screen size with the SystemParameters class in C#.

using System.Windows;

double height = SystemParameters.FullPrimaryScreenHeight;
double width = SystemParameters.FullPrimaryScreenWidth;
double resolution = height * width

The above code calculates the primary screen’s resolution by taking the product of height and width variables.

Get Screen Size of All Screens With the SystemParameters Class in C#

In the previous section, we only calculated the resolution of the primary screen. But, if we use a multi-screen setup and want to get the combined size of all the screens, we can also do this with the SystemParameters class in C#. The SystemParameters.VirtualScreenHeight property gets the full height of all the monitors. The SystemParameters.VirtualScreenWidth property gets the width of all the monitors. We can use both these properties to get the combined size of all the monitors. The following code example shows us how we can get all the monitors’ screen size with the SystemParameters class in C#.

using System.Windows;

double height = SystemParameters.VirtualScreenHeight;
double width = SystemParameters.VirtualScreenWidth;
double resolution = height * width

The above code gets all the screens’ resolution by taking the product of height and width variables.

Muhammad Maisam Abbas avatar Muhammad Maisam Abbas avatar

Maisam is a highly skilled and motivated Data Scientist. He has over 4 years of experience with Python programming language. He loves solving complex problems and sharing his results on the internet.

LinkedIn