views:

271

answers:

2

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

Any help is certainly appreciated.`

A: 

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

Robert Harvey
+1  A: 

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"]);
    }
}
Daniel Brückner
Thank you for the response Daniel.I have been struggling with this for sometime now. With your above answer, I don't see how it relates to individual screens. With my dual displays setup, my video card may support up to 1900x1200, but my attached monitor has a max of 1280x1024. I don't see how to query for the resolutions for the individual displays...
You will have to search through the available WMI classes ... I am quite confident that there is a class providing the information you are looking for. Go to http://msdn.microsoft.com/en-us/library/aa394554(VS.85).aspx and search through the classes.
Daniel Brückner