Source: C # API gets system DPI zoom multiple and resolution size
Using System; Using System.Drawing; Using System.Runtime.InteropServices; Namespace Xydes {public class PrimaryScreen {#region Win32 API [DllImport ("user32.d ll ")] static extern IntPtr GetDC (IntPtr ptr); [DllImport ("Gdi32.dll")] static extern int GetDeviceCaps (INTPTR hdc,//Handle to DC int NIndex//index of capability); [DllImport ("user32.dll", EntryPoint = "ReleaseDC")] static extern IntPtr ReleaseDC (IntPtr hWnd, IntPtr H DC); #endregion #region DeviceCaps constant const int horzres = 8; const int vertres = 10; const int LOGPIXELSX = 88; const int logpixelsy = 90; const int desktopvertres = 117; const int desktophorzres = 118; #endregion #region Properties//<summary>///Get screen resolution current physical size///</summary> public static size Workingarea { get {IntPtr hdc = GetDC (IntPtr.Zero); Size size = new size (); Size. Width = GetDeviceCaps (hdc, horzres); Size. Height = GetDeviceCaps (hdc, vertres); ReleaseDC (IntPtr.Zero, HDC); return size; }}///<summary>///current system dpi_x size is usually///</summary> public static int Dpix {get {IntPtr hdc = GetDC (in Tptr.zero); int Dpix = GetDeviceCaps (hdc, LOGPIXELSX); ReleaseDC (IntPtr.Zero, HDC); return Dpix; }}///<summary>//Current system dpi_y size is generally </summary&Gt public static int Dpiy {get {IntPtr hdc = GetDC (intp Tr. Zero); int Dpix = GetDeviceCaps (Hdc,logpixelsy); ReleaseDC (IntPtr.Zero, HDC); return Dpix; }}///<summary>//Get the desktop resolution size of the real setting///</summary> P Ublic static Size DESKTOP {get {IntPtr hdc = GetDC (I Ntptr.zero); Size size = new size (); Size. Width = GetDeviceCaps (hdc,desktophorzres); Size. Height = GetDeviceCaps (hdc, desktopvertres); ReleaseDC (IntPtr.Zero, HDC); return size; }}///<summary>//Get width Scaling percentage///</summary> public static Float ScaleX {get {IntPtr hdc = GetDC (IntPtr.Zero); int t = GetDeviceCaps (hdc, desktophorzres); int d = GetDeviceCaps (hdc, horzres); float ScaleX = (float) getdevicecaps (hdc, desktophorzres)/(float) getdevicecaps (hdc, horzres); ReleaseDC (IntPtr.Zero, HDC); return ScaleX; }}///<summary>//Get height Scaling percentage///</summary> public static float ScaleY {get {IntPtr hdc = getd C (IntPtr.Zero); float ScaleY = (float) (float) GetDeviceCaps (hdc, desktopvertres)/(float) getdevicecaps (hdc, vertres); ReleaseDC (IntPtr.Zero, HDC); return ScaleY; }} #endregion}}
C # API Get system DPI zoom multiple and resolution size