开发者

List of valid resolutions for a given Screen?

开发者 https://www.devze.com 2022-12-08 01:13 出处:网络
Is there a way to get ALL valid resolutions for a given screen? I currently have a dropdown开发者_JAVA技巧 that is populated with all valid screens (using Screen.AllScreens).When the user selects a s

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

I currently have a dropdown开发者_JAVA技巧 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).


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消