How Many Connected Screens?

By | 2023-01-09

To determine the number of monitors connected to a computer with C#, you can use the System.Windows.Forms.Screen class, which provides a static AllScreens property that returns an array of Screen objects, one for each display device connected to the computer. You can then use the Length property of the array to determine the number of screens.

Here’s an example of how you could use this approach:

int numScreens = System.Windows.Forms.Screen.AllScreens.Length;

This will give you the number of screens connected to the computer. You can then use the Screen objects in the array to get information about each screen, such as its bounds, working area, and primary status.

Here’s an example of how you could iterate through the Screen objects in the AllScreens array and print out information about each screen:

foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
{
 Console.WriteLine("Device Name: " + screen.DeviceName);
 Console.WriteLine("Bounds: " + screen.Bounds);
 Console.WriteLine("Working Area: " + screen.WorkingArea);
 Console.WriteLine("Primary: " + screen.Primary);
}

This will print out information about each screen connected to the computer, including the device name, bounds, working area, and whether the screen is the primary screen.

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.