How would one poll windows to see what monitors are attached and what resolution they are running at?
3 Answers
In C#: Screen
Class Represents a display device or multiple display devices on a single system. You want the Bounds
attribute.
foreach(var screen in Screen.AllScreens)
{
// For each screen, add the screen properties to a list box.
listBox1.Items.Add("Device Name: " + screen.DeviceName);
listBox1.Items.Add("Bounds: " + screen.Bounds.ToString());
listBox1.Items.Add("Type: " + screen.GetType().ToString());
listBox1.Items.Add("Working Area: " + screen.WorkingArea.ToString());
listBox1.Items.Add("Primary Screen: " + screen.Primary.ToString());
}

- 25,416
- 6
- 48
- 54
-
4By using `foreach (Screen screen in Screen.AllScreens)` this looks even better. – Max Truxa Jul 25 '13 at 13:23
-
Indeed. When I answered, I didn't know C# :) – Joe Koberg Jul 29 '13 at 18:55
-
This only shows one monitor when running from a service, is there a work around? – Steve Byrne Jul 09 '15 at 17:19
-
1This only reports 1 if there are 2 monitors connected and the display is mirrored. – Matt Becker Dec 28 '16 at 21:58
Use the Screen class.
You can see all of the monitors in the Screen.AllScreens
array, and check the resolution and position of each one using the Bounds
property.
Note that some video cards will merge two monitors into a single very wide screen, so that Windows thinks that there is only one monitor. If you want to, you could check whether the width of a screen is more than twice its height; if so, it's probably a horizontal span and you can treat it as two equal screens. However, this is more complicated and you don't need to do it. Vertical spans are also supported but less common.

- 868,454
- 176
- 1,908
- 1,964
http://msdn.microsoft.com/en-us/magazine/cc301462.aspx
GetSystemMetrics is a handy function you can use to get all sorts of global dimensions, like the size of an icon or height of a window caption. In Windows 2000, there are new parameters like SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN to get the virtual size of the screen for multiple monitor systems. Windows newbies—and pros, too—should check out the documentation for GetSystemMetrics to see all the different system metrics (dimensions) you can get. See the Platform SDK for the latest at http://msdn.microsoft.com/library/en-us/sysinfo/sysinfo_8fjn.asp. GetSystemMetrics is a handy function you frequently need to use, and new stuff appears with every version of Windows.

- 6,294
- 3
- 24
- 19
-
This is very cool. There is managed code for most of this stuff... For instance, the `System.Windows.Forms.SystemInformation` class likely contains a majority. – brandeded Oct 22 '13 at 17:08