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