日期:2014-05-17 浏览次数:20926 次
private void Form1_Load(object sender, EventArgs e)
{
//获取系统DPI
try
{
SetProcessDPIAware(); //重要
IntPtr screenDC = GetDC(IntPtr.Zero);
int dpi_x = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSX);
int dpi_y = GetDeviceCaps(screenDC, /*DeviceCap.*/LOGPIXELSY);
CommonInfo.scaleUIX = dpi_x / 96.0;//横向系数
CommonInfo.scaleUIY = dpi_y / 96.0;//纵向系数
ReleaseDC(IntPtr.Zero, screenDC);
}
catch (Exception)
{
//throw;
//没有管理员权限就获取不到了
}
}
/*----------------------------------------获取系统DPI-----------------------------------------------------*/
[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 ext