winforms-hdpi-changes-48.md
August 20, 2019 ยท View on GitHub
High DPI (HDPI) improvements in Windows Forms controls for .NET 4.8
Scope
Major
Version Introduced
4.8
Source Analyzer Status
NotPlanned
Change Description
The Windows Forms Framework is continuing to improve the scaling and rendering of its controls to better support Windows Forms customers on high resolution devices. As a result of these improvemeents, Windows Forms applications are able to better handle DPI changes that occur, for example, when moving the application from one monitor to another monitor that has different DPI settings. These include the following changes:
-
Changes to improve the scaling of xref:System.Windows.Forms.PropertyGrid controls when the DPI of the application changes.
-
Changes to improve the scaling of Toolstrip menus, buttons, and glyphs when the DPI of the application changes.
-
Changes to improve the scaling of xref:System.Windows.Forms.RadioButton and xref:System.Windows.Forms.CheckBox controls when setting different styles on them, and the DPI of the application changes.
-
Changes to improve the scaling of font-based controls when the DPI of the application changes.
-
Changes to improve the scaling of the xref:System.Windows.Forms.Button control when the DPI of the application changes.
-
Quirked
-
Build-time break
Recommended Action
How to opt in or out of these changes
In order for the application to benefit from these changes, it must run on the .NET Framework 4.8. The application can opt in to these changes in either of the following ways:
- It is recompiled to target the .NET Framework 4.8. These high DPI improvement changes are enabled by default on Windows Forms applications that target the .NET Framework 4.8.
- It targets the .NET Framework 4.7.2 or earlier versions and opts in to this new behaviour by adding the following Windows Forms Configuration Section to the app config file and then adding the required flag to opt-in specific feature improvements.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
</startup>
<configuration>
<System.Windows.Forms.ApplicationConfigurationSection>
...
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
</configuration>
- High DPI improvements in each major category has its own opt-in setting. Applications can set the required setting by following instructions found at High DPI support in Windows Forms and the Windows Forms add configuration element .
Note that many of these improvements are enabled only on Windows 10, and your application must be enabled to run in Windows 10 compatible mode. You can set this in the application manifest file as defined in High DPI support in Windows Forms.
__Opting out
Applications that target the .NET Framework 4.8 and want to preserve the legacy high dpi behavior can do so by explicitly setting the switches described below to true.
Improved PropertyGrid scaling when DPI changes.
- Improved scaling of the PropertyGrid control and its child controls when the DPI of the application is changed (for example, when the application moves from one monitor to another with different DPI settings). All changes made for this improvement are controlled by the
DisableDpiChangedHighDpiImprovementsswitch.
Improved scaling of Toolstrip Menus/Buttons/Glyphs when the DPI of the application changed
All changes in this area are controlled by the ToolStrip.DisableHighDpiImprovements & DisableDpiChangedHighDpiImprovements switches.
Improved scaling of RadioButton and CheckBox when application DPI changes
- Improved the scaling of the RadioButton and CheckBox, when setting different styles on them and the DPI of the application changes. All changes made for this improvement are quirked under the
DisableDpiChangedHighDpiImprovementsswitch.
Improved scaling of Button control when application DPI changed
All changes made in this area are controlled by the DisableDpiChangedHighDpiImprovements switch.
Improved scaling of Font based controls when application DPI changes
All changes made in this area are controlled by the DisableDpiChangedHighDpiImprovements switch.
Affected APIs
- Not detectable via API analysis.
Category
Windows Forms