/// <summary> /// Checks if configuration setting is set to expected value /// </summary> /// <param name="configurationSettingName">Configuration setting name</param> /// <param name="expectedValue">Expected value</param> /// <returns>true/false</returns> internal static bool IsExpectedConfigValue(string configurationSettingName, bool expectedValue) { string value = ConfigurationOptions.GetConfigSettingValue(configurationSettingName); if (!bool.TryParse(value, out bool valueAsBool)) { // neither 'true' nor 'false' - implies 'false' valueAsBool = false; } return(valueAsBool == expectedValue); }
internal static bool IsDpiAwarenessValueSet() { bool dpiAwarenessValueSet = false; try { if (string.IsNullOrEmpty(dpiAwarenessValue)) { dpiAwarenessValue = ConfigurationOptions.GetConfigSettingValue(ConfigurationStringConstants.DpiAwarenessKeyName); } } catch { } if (!string.IsNullOrEmpty(dpiAwarenessValue)) // setting in configuration wins { var value = dpiAwarenessValue.ToLowerInvariant(); switch (value) { case "true": case "system": case "true/pm": case "permonitor": case "permonitorv2": dpiAwarenessValueSet = true; break; case "false": System.Diagnostics.Debug.WriteLine(" 'DpiAwarenessValue' is set to 'false', value = " + value); break; default: System.Diagnostics.Debug.WriteLine("Either 'DpiAwarenessValue' is not set or 'DpiAwarenessValue' set is invalid in app.config, value set = " + value); break; } } return(dpiAwarenessValueSet); }
internal static void InitializeDpiHelperQuirks() { if (isDpiHelperQuirksInitialized) { return; } try { // Redstone 2 or greater, where all APIs required by this feature are available if ((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; }