首先添加引用:using System.Management;
[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, // 驅(qū)動(dòng)名稱 string lpszDevice, // 設(shè)備名稱 string lpszOutput, // 可設(shè)置為null Int64 lpInitData // optional PRinter data ); [DllImport("gdi32.dll")] public static extern int GetDeviceCaps( IntPtr hdc, // handle to DC int nIndex // index of capability ); [DllImport("user32.dll")] internal static extern bool SetProcessDPIAware(); const int LOGPIXELSX = 88; const int LOGPIXELSY = 90;//在方法中添加如下代碼進(jìn)行獲取SetProcessDPIAware(); //這句很重要 IntPtr screenDC = GetDC(IntPtr.Zero); int dpi_x = GetDeviceCaps(screenDC, LOGPIXELSX);//96 是100%、120 是125% int dpi_y = GetDeviceCaps(screenDC,LOGPIXELSY); ReleaseDC(IntPtr.Zero, screenDC);
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注