public static bool GetDPIForMonitor(Display display, ref Point dpi) { Version os = WindowsVersionInfo.Version; if (os.Major > 6 || os.Major == 6 && os.Minor >= 3) { uint dpiX = 0; uint dpiY = 0; bool result = User32Interop.GetDpiForMonitor(display.Handle, MonitorDpiType.RawDPI, ref dpiX, ref dpiY); dpi = new Point((int)dpiX, (int)dpiY); return(result); } else { int mDpi = (int)(GetDPIScalingFactor() * 96); dpi = new Point(mDpi, mDpi); return(true); } }
public static bool GetDPIForMonitor(Display display, ref Point dpi) { Version os = WindowsVersionInfo.Version; if (os.Major > 6 || os.Major == 6 && os.Minor >= 3) { uint dpiX = 0; uint dpiY = 0; User32Interop.GetDpiForMonitor(display.Handle, User32Interop.DpiType.Effective /*MonitorDpiType.RawDPI*/, out dpiX, out dpiY); dpi = new Point((int)dpiX, (int)dpiY); return true; } else { int mDpi = (int)(GetDPIScalingFactor() * 96); dpi = new Point(mDpi, mDpi); return true; } }