Exemplo n.º 1
0
        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();
        }