Search code examples
c#-4.0screenresolutionscreen-resolution

Access User's Possible Screen Resolutions - C# 2010


Thanks in advance for your help.

I am wondering how I might go about accessing the screen resolutions available on a user's PC. I would like to get a list of all available resolutions and also determine what the user is current running at.


Solution

  • I believe you can make a PInvoke call to EnumDisplaySettings api call in User32.dll.

    [DllImport("user32.dll")]
    public static extern bool EnumDisplaySettings (string deviceName, int modeNum, ref DEVMODE devMode );
    

    See example here.

    You'll of course run into complications with dual-monitor systems, but to get the current screen you can do

    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
    

    I assumed you were talking about an executable and not an ASP.Net app, but if you need the screen size in Javascript, you can use the screen object.

    screen.width; screen.height; screen.colorDepth;