/// <summary>
/// 获取dpi值
/// </summary>
/// <param name="dpiValue"></param>
/// <param name="form"></param>
public static void setDpiValue(float dpiValue,Form form) {
float dpiX;
//直接在load事件,最好
//Graphics graphics = this.CreateGraphics();
Graphics graphics = form.CreateGraphics();
dpiX = graphics.DpiX;
switch (dpiX)
{
case 96f:
dpiValue = 1.0f;
break;
case 120f:
dpiValue = 1.25f;
break;
case 144f:
dpiValue = 1.5f;
break;
case 168f:
dpiValue = 1.75f;
break;
case 192f:
dpiValue = 2.0f;
break;
}
FormResize.setDpiValue(dpiValue, this);
foreach (Control c in form.Controls)
{
Single size = Convert.ToSingle(c.Font.Size * dpiValue);
}