Search code examples
c#resolution

List of valid resolutions for a given Screen?


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


Solution

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