Esempio n. 1
0
        internal static void InitializeDpiHelperQuirks()
        {
            if (isDpiHelperQuirksInitialized)
            {
                return;
            }
            try
            {
                // Redstone 2 or greater, where all APIs required by this feature are available
                if ((Environment.OSVersion.Platform == System.PlatformID.Win32NT) &&
                    (Environment.OSVersion.Version.CompareTo(ConfigurationOptions.RS2Version) >= 0) &&
                    (IsExpectedConfigValue(ConfigurationStringConstants.DisableDpiChangedMessageHandlingKeyName, false)) &&
                    (IsDpiAwarenessValueSet()) &&
                    // The dynamic scaling features are implemented only in comclt32 v6, no point to
                    // activate it otherwise.
                    (Application.RenderWithVisualStyles))
                {
                    // user had not opted out from dynamic scaling level changes but the primary screen DPI might be 96
                    enableDpiChangedMessageHandling = true;
                }

                // IsScalingRequired returns true if the current resolution is not 96DPI on the primary monitor.
                // However PerMonitor DPI aware applicaitons need dynamic scaling initialized properly even if the
                // the current DPI is 96 because they handle DPI change.
                if ((DpiHelper.IsScalingRequired || enableDpiChangedMessageHandling) && IsDpiAwarenessValueSet())
                {
                    if (IsExpectedConfigValue(ConfigurationStringConstants.CheckedListBoxDisableHighDpiImprovementsKeyName, false))
                    {
                        enableCheckedListBoxHighDpiImprovements = true;
                    }

                    if (IsExpectedConfigValue(ConfigurationStringConstants.ToolStripDisableHighDpiImprovementsKeyName, false))
                    {
                        enableToolStripHighDpiImprovements = true;
                    }

                    if (IsExpectedConfigValue(ConfigurationStringConstants.FormDisableSinglePassScalingOfDpiFormsKeyName, false))
                    {
                        enableSinglePassScalingOfDpiForms = true;
                    }

                    if (IsExpectedConfigValue(ConfigurationStringConstants.DataGridViewControlDisableHighDpiImprovements, false))
                    {
                        enableDataGridViewControlHighDpiImprovements = true;
                    }

                    if (IsExpectedConfigValue(ConfigurationStringConstants.AnchorLayoutDisableHighDpiImprovementsKeyName, false))
                    {
                        enableAnchorLayoutHighDpiImprovements = true;
                    }

                    if (IsExpectedConfigValue(ConfigurationStringConstants.MonthCalendarDisableHighDpiImprovementsKeyName, false))
                    {
                        enableMonthCalendarHighDpiImprovements = true;
                    }

                    if (ConfigurationOptions.GetConfigSettingValue(ConfigurationStringConstants.DisableDpiChangedHighDpiImprovementsKeyName) == null)
                    {
                        if (ConfigurationOptions.NetFrameworkVersion.CompareTo(dpiChangedMessageHighDpiImprovementsMinimumFrameworkVersion) >= 0)
                        {
                            enableDpiChangedHighDpiImprovements = true;
                        }
                    }
                    else
                    {
                        if (IsExpectedConfigValue(ConfigurationStringConstants.DisableDpiChangedHighDpiImprovementsKeyName, false))
                        {
                            enableDpiChangedHighDpiImprovements = true;
                        }
                    }

                    // no opt-out switch at the moment
                    enableThreadExceptionDialogHighDpiImprovements = true;
                }
            }
            catch
            {
            }

            isDpiHelperQuirksInitialized = true;
        }