How can I retrieve the screen resolution that my C# Winform App is running on?
5 Answers
Do you need just the area a standard application would use, i.e. excluding the Windows taskbar and docked windows? If so, use the Screen.WorkingArea property. Otherwise, use Screen.Bounds.
If there are multiple monitors, you need to grab the screen from your form, i.e.
Form myForm;
Screen myScreen = Screen.FromControl(myForm);
Rectangle area = myScreen.WorkingArea;
If you want to know which is the primary display screen, use the Screen.Primary property. Also, you can get a list of screens from the Screen.AllScreens property.

- 16,585
- 5
- 47
- 82
-
4+1 for Screen.WorkingArea. I had mistakenly been using Screen.Bounds. I'd give you +2 if I could, for mentioning Screen.FromControl instead of Screen.PrimaryScreen! – ToolmakerSteve Oct 10 '13 at 17:44
The given answer is correct, as far as it goes. However, when you have set your Text size to anything more than 125%, Windows (and .NET) start to fib about the size of the screen in order to do auto-scaling for you.
Most of the time, this is not an issue - you generally want Windows and .NET to do this. However, in the case where you really, truly need to know the actual count of pixels on the screen (say, you want to paint directly to the desktop DC), you can do the following. I've only tried this on Win10. YMMV on other Windows versions.
So far, this is the only way I've found to get true screen pixel count if you don't want to globally turn off DPI awareness in your app. Note that this example gets the Primary display size - you will need to modify this to get other screens.
[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
static extern int ReleaseDC(IntPtr hwnd, IntPtr dc);
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
IntPtr primary = GetDC(IntPtr.Zero);
int DESKTOPVERTRES = 117;
int DESKTOPHORZRES = 118;
int actualPixelsX = GetDeviceCaps(primary, DESKTOPHORZRES);
int actualPixelsY = GetDeviceCaps(primary, DESKTOPVERTRES);
ReleaseDC(IntPtr.Zero, primary);

- 473
- 5
- 9
-
Can you get the real screen size if there are scale factor of your windows (100% / 125% / 150% / 200%). ? – Kiquenet Jul 23 '19 at 13:00
-
@Kiquenet - yes, the above code gets the actual (raw) pixel count of the screen independent of any scaling. Note that the example code is for primary screen - you will need to modify the GetDC call if you want pixel count from non-primary screen. – entiat Dec 17 '21 at 18:06
-
Your solution, together with [this one](https://stackoverflow.com/a/15714546/107625) helped me solve this on a per-monitor-basis. – Uwe Keim Feb 27 '22 at 13:42
Use the Screen class, and interrogate the Bounds property. The Screen class has a static property for Primary Screen, and another static property that returns a list of all the screens attached to the system.

- 5,875
- 1
- 27
- 38
Here is what I have used to get the screen resolution of the Working Area where my mouse pointer is. I can start my program and then move my mouse to another monitor and get that resolution.
internal static void GetScreenResolution(ref double screenX, ref double screenY)
{
Screen myScreen = Screen.FromPoint(Cursor.Position);
System.Drawing.Rectangle area = myScreen.WorkingArea;
screenX = area.Width;
screenY = area.Height;
}
Maybe not the best solution, but I can generate a scaling factor and use it scale my controls.
I used this in a WPF program and I had to add a reference System.Windows.Forms
I also put it in a separate class so I would not get conflicts in my main code.

- 2,917
- 23
- 46
- 68