Find Number and resolution to all monitors
Asked Answered
B

3

41

How would one poll windows to see what monitors are attached and what resolution they are running at?

Buffo answered 8/10, 2009 at 15:38 Comment(0)
C
68

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());
}
Conveyor answered 8/10, 2009 at 15:43 Comment(4)
By using foreach (Screen screen in Screen.AllScreens) this looks even better.Postlude
Indeed. When I answered, I didn't know C# :)Conveyor
This only shows one monitor when running from a service, is there a work around?Lamppost
This only reports 1 if there are 2 monitors connected and the display is mirrored.Eye
C
7

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.

Canales answered 8/10, 2009 at 15:47 Comment(0)
P
4

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.

Philips answered 8/10, 2009 at 15:42 Comment(1)
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.Dragnet

© 2022 - 2024 — McMap. All rights reserved.