private static void SetThreadDPI(DpiScalingMethod eMethod) { if (Environment.OSVersion.Version < new Version(10, 0, 15063)) // Windows 10 Creators Update added SetThreadDpiAwarenessContext { SetProcessDPI(eMethod); return; } switch (eMethod) { case DpiScalingMethod.None: NativeMethods.SetThreadDpiAwarenessContext(NativeMethods.ContextDpiAwareness.Unaware); break; // System case DpiScalingMethod.Zoom: NativeMethods.SetThreadDpiAwarenessContext(NativeMethods.ContextDpiAwareness.System); break; // PerMonitor/PerMonitorV2 case DpiScalingMethod.Rescale: NativeMethods.SetThreadDpiAwarenessContext(NativeMethods.ContextDpiAwareness.PerMonitorV2); break; // System (Enhanced) case DpiScalingMethod.SmartZoom: NativeMethods.SetThreadDpiAwarenessContext( Environment.OSVersion.Version >= new Version(10, 0, 17763) ? NativeMethods.ContextDpiAwareness.UnawareGdiScaled // Windows 10 Version 1809 Added GDI+ Scaling : NativeMethods.ContextDpiAwareness.System); // System as backup, because it's better than remaining unaware if we want GDI+ Scaling break; default: throw new ArgumentOutOfRangeException(nameof(eMethod), eMethod, null); } Utils.BreakOnErrorIfDebug(); }
private static void SetProcessDPI(DpiScalingMethod eMethod) { switch (eMethod) { case DpiScalingMethod.None: if (Environment.OSVersion.Version >= new Version(6, 3, 0)) // Windows 8.1 added SetProcessDpiAwareness { if (Environment.OSVersion.Version >= new Version(10, 0, 15063)) // Windows 10 Creators Update added SetProcessDpiAwarenessContext { NativeMethods.SetProcessDpiAwarenessContext(NativeMethods.ContextDPIAwareness.Unaware); } else { NativeMethods.SetProcessDpiAwareness(NativeMethods.ProcessDPIAwareness.Unaware); } } break; // System case DpiScalingMethod.Zoom: if (Environment.OSVersion.Version >= new Version(6, 3, 0)) // Windows 8.1 added SetProcessDpiAwareness { if (Environment.OSVersion.Version >= new Version(10, 0, 15063)) // Windows 10 Creators Update added SetProcessDpiAwarenessContext { NativeMethods.SetProcessDpiAwarenessContext(NativeMethods.ContextDPIAwareness.System); } else { NativeMethods.SetProcessDpiAwareness(NativeMethods.ProcessDPIAwareness.System); } } else { NativeMethods.SetProcessDPIAware(); } break; // PerMonitor/PerMonitorV2 case DpiScalingMethod.Rescale: if (Environment.OSVersion.Version >= new Version(6, 3, 0)) // Windows 8.1 added SetProcessDpiAwareness { if (Environment.OSVersion.Version >= new Version(10, 0, 15063)) // Windows 10 Creators Update added SetProcessDpiAwarenessContext and PerMonitorV2 { NativeMethods.SetProcessDpiAwarenessContext(NativeMethods.ContextDPIAwareness.PerMonitorV2); } else { NativeMethods.SetProcessDpiAwareness(NativeMethods.ProcessDPIAwareness.PerMonitor); } } else { NativeMethods.SetProcessDPIAware(); // System as backup, because it's better than remaining unaware if we want PerMonitor/PerMonitorV2 } break; // System (Enhanced) case DpiScalingMethod.SmartZoom: if (Environment.OSVersion.Version >= new Version(6, 3, 0)) // Windows 8.1 added SetProcessDpiAwareness { if (Environment.OSVersion.Version >= new Version(10, 0, 15063)) // Windows 10 Creators Update added SetProcessDpiAwarenessContext { NativeMethods.SetProcessDpiAwarenessContext( Environment.OSVersion.Version >= new Version(10, 0, 17763) ? NativeMethods.ContextDPIAwareness.UnawareGdiScaled // Windows 10 Version 1809 Added GDI+ Scaling : NativeMethods.ContextDPIAwareness.System); // System as backup, because it's better than remaining unaware if we want GDI+ Scaling } else { NativeMethods.SetProcessDpiAwareness(NativeMethods.ProcessDPIAwareness.System); } } else { NativeMethods.SetProcessDPIAware(); // System as backup, because it's better than remaining unaware if we want GDI+ Scaling } break; default: throw new ArgumentOutOfRangeException(nameof(eMethod), eMethod, null); } }