C# 查找所有显示器的编号和分辨率
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1538602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find Number and resolution to all monitors
提问by Crash893
How would one poll windows to see what monitors are attached and what resolution they are running at?
如何轮询窗口以查看连接了哪些显示器以及它们以什么分辨率运行?
采纳答案by Joe Koberg
In C#: Screen
ClassRepresents a display device or multiple display devices on a single system. You want the Bounds
attribute.
在 C# 中:Screen
Class表示单个系统上的一个显示设备或多个显示设备。你想要这个Bounds
属性。
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());
}
回答by somacore
http://msdn.microsoft.com/en-us/magazine/cc301462.aspx
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.
GetSystemMetrics 是一个方便的函数,您可以使用它来获取各种全局尺寸,例如图标的大小或窗口标题的高度。在 Windows 2000 中,有像 SM_CXVIRTUALSCREEN 和 SM_CYVIRTUALSCREEN 这样的新参数来获取多个监视器系统的屏幕虚拟大小。Windows 新手和专业人士也应该查看 GetSystemMetrics 的文档以查看您可以获得的所有不同系统指标(维度)。有关最新信息,请参阅http://msdn.microsoft.com/library/en-us/sysinfo/sysinfo_8fjn.asp 上的 Platform SDK 。GetSystemMetrics 是一个您经常需要使用的方便功能,并且每个版本的 Windows 都会出现新的东西。
回答by SLaks
Use the Screen class.
使用Screen 类。
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.
您可以查看Screen.AllScreens
阵列中的所有显示器,并使用该Bounds
属性检查每个显示器的分辨率和位置。
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.
请注意,有些显卡会将两台显示器合并为一个非常宽的屏幕,因此 Windows 认为只有一台显示器。如果你愿意,你可以检查屏幕的宽度是否是高度的两倍以上;如果是这样,它可能是一个水平跨度,您可以将其视为两个相等的屏幕。但是,这更复杂,您不需要这样做。也支持垂直跨度,但不太常见。