给定屏幕的有效分辨率列表? [英] List of valid resolutions for a given Screen?
问题描述
有没有一种方法可以获取给定屏幕的所有有效分辨率?
Is there a way to get ALL valid resolutions for a given screen?
我目前有一个下拉菜单,其中包含所有有效屏幕(使用 Screen.AllScreens ).当用户选择屏幕时,我想向他们显示第二个下拉列表,列出该显示的所有有效分辨率(不是仅是当前分辨率).
I currently have a dropdown that is populated with all valid screens (using Screen.AllScreens). When the user selects a screen, I'd like to present them with a second dropdown listing all valid resolutions for that display (not just the current resolution).
推荐答案
我认为应该可以使用 System.Management 名称空间.
I think it should be possible to get the information using Windows Management Instrumentation (WMI). WMI is accessible from .NET using the classes from them System.Management namespace.
解决方案将类似于以下内容.我不太了解WMI,无法立即找到您要查找的信息,但是我找到了视频卡支持的分辨率的WMI类.该代码需要引用System.Management.dll并导入System.Management命名空间.
A solution will look similar to the following. I don't know WMI well and could not immediately find the information you are looking for, but I found the WMI class for the resolutions supported by the video card. The code requires referencing System.Management.dll and importing the System.Management namespace.
var scope = new ManagementScope();
var query = new ObjectQuery("SELECT * FROM CIM_VideoControllerResolution");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
var results = searcher.Get();
foreach (var result in results)
{
Console.WriteLine(
"caption={0}, description={1} resolution={2}x{3} " +
"colors={4} refresh rate={5}|{6}|{7} scan mode={8}",
result["Caption"], result["Description"],
result["HorizontalResolution"],
result["VerticalResolution"],
result["NumberOfColors"],
result["MinRefreshRate"],
result["RefreshRate"],
result["MaxRefreshRate"],
result["ScanMode"]);
}
}
这篇关于给定屏幕的有效分辨率列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!