List of valid resolutions for a given Screen?

岁酱吖の 提交于 2020-01-16 04:32:04

问题


Is there a way to get ALL valid resolutions for a given screen?

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).


回答1:


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.

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"]);
    }
}



回答2:


The following link contains detailed code examples for this:

Task 2: Changing the Display Resolution
http://msdn.microsoft.com/en-us/library/aa719104(VS.71).aspx#docum_topic2




回答3:


The accepted answer doesn't seem to work on Windows 8.1, at least on my machine. The query runs fine but there are 0 entries in the results. And considering Bijoy K Jose's comment I suppose that I am not the only one.

However the validated answer for the following question worked out just fine : How to list available video modes using C#?

Thanks to Vimvq1987



来源:https://stackoverflow.com/questions/1528266/list-of-valid-resolutions-for-a-given-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!