using System; using System.Drawing; using System.Windows.Forms; namespace JinYuan.ControlLib.UCHelper { /// /// 系统缩放比例 /// public class DpiHelper { #region 公开方法 /// /// 获取控件对应的系统缩放比例 /// /// /// public static float GetControlDpi(Control control) { IntPtr hDC = IntPtr.Zero; Graphics g = null; ControlHelper.GetWindowClientGraphics(control.Handle, out g, out hDC); float dpi = g.DpiX / 96f; g.Dispose(); NativeMethods.ReleaseDC(control.Handle, hDC); return dpi; } /// /// 获取控件对应的系统缩放比例 /// /// /// public static float GetControlDpi(IntPtr hWnd) { IntPtr hDC = IntPtr.Zero; Graphics g = null; ControlHelper.GetWindowClientGraphics(hWnd, out g, out hDC); float dpi = g.DpiX / 96f; g.Dispose(); NativeMethods.ReleaseDC(hWnd, hDC); return dpi; } #endregion } }