Get System dpi

Source: Internet
Author: User

Public partial class Form1:form {Public Form1 (){InitializeComponent (); setprocessdpiaware (); //Important IntPtr SCREENDC = GetDC (IntPtr.Zero); int dpi_x = GetDeviceCaps (SCREENDC,/*devicecap.*/LOGPIXELSX); int dpi_y = GetDeviceCaps (SCREENDC,/*devicecap.*/Logpixelsy);//_scaleui.x = dpi_x/96.0;//_SCALEUI.Y = dpi_y/96.0;ReleaseDC (IntPtr.Zero, SCREENDC);         } [DllImport ("User32.dll")] static extern IntPtr GetDC (IntPtr ptr);          [DllImport ("user32.dll", EntryPoint = "ReleaseDC")] public static extern IntPtr ReleaseDC (IntPtr hWnd, IntPtr hDc); [DllImport ("Gdi32.dll")] public static extern IntPtr CreateDC (String lpszdriver,//driver nameString Lpszdevice,//Device nameString Lpszoutput,//not used; should is NULLInt64 Lpinitdata//Optional printer Data); [DllImport ("Gdi32.dll")] public static extern int GetDeviceCaps (INTPTR hdc,//Handle to DCint NIndex//Index of Capability       );         [DllImport (" User32.dll ")]        internal static extern bool Setprocessdpiaware ();          const int driverversion = 0;        const INT technology = 2;        const int horzsize = 4;         const INT vertsize = 6;        const int horzres = 8;  & nbsp;     const INT vertres = 10;        const int BITSPIXEL = 12 ;        const INT PLANES = 14;        Const int numbrushes = 16;        const int numpens = 18;     & nbsp;  const int nummarkers = 20;        Const int numfonts = 22;        const int numcolors = 24;         const INT pdevicesize = 26;        const int curvecaps = 28;         const INT linecaps = 30;        const int Polygonalcaps = 32;        const int textcaps = 34;     & nbsp;  const INT clipcaps = 36;        const int rastercaps = 38;  & nbsp;     const INT ASPECTX = 40;        const int ASPECTY = 42;& nbsp;       const INT ASPECTXY = 44;        Const int shadeblendcaps = 45;        const int LOGPIXELSX = 88;    & nbsp;   const int logpixelsy = 90;        const INT sizepalette = 104;        const int NUMRESERVED = 106;        const int colorres = 108;        const INT physicalwidth = 110;        const int physicalheight = 111;  & nbsp;     const INT PHYSICALOFFSETX = 112;        const int Physicaloffsety = 113;        const int Scalingfactorx = 114;         const INT scalingfactory = 115;        const int VRefresh = 116;        const int desktopvertres = 117;         const INT desktophorzres = 118;        const int bltalignment = 119;}

Get system dpi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.