Академический Документы
Профессиональный Документы
Культура Документы
• 16/05/2017
Starting with the .NET Framework 4.7, Windows Forms includes enhancements for common
high DPI and dynamic DPI scenarios. These include:
In versions of the .NET Framework starting with the .NET Framework 4.7, enhanced high
DPI support is an opt-in feature. You must configure your application to take advantage of
it.
In addition, to configure high DPI support in your Windows Forms application, you must
do the following:
XML
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 compatibility -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
Enable per-monitor DPI awareness in the app.config file.
XML
<System.Windows.Forms.ApplicationConfigurationSection>
</System.Windows.Forms.ApplicationConfigurationSection>
element to support new features and customizations added starting with the .NET
Framework 4.7. To take advantage of the new features that support high DPI, add the
following to your application configuration file.
Important
In previous versions of the .NET Framework, you used the manifest to add high DPI
support. This approach is no longer recommended, since it overrides settings defined on
the app.config file.
This should be the first method call in your application entry point. For example:
C#
XML
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
<add key="EnableWindowsFormsHighDpiAutoResizing" value="false" />
</System.Windows.Forms.ApplicationConfigurationSection>
For a list of individual keys and their values, see Windows Forms Add Configuration
Element.
• DpiChangedAfterParent, which is fired when the DPI setting for a control is changed
programmatically after a DPI change event for it's parent control or form has
occurred.
• DpiChangedBeforeParent, which is fired when the DPI setting for a control is
changed programmatically before a DPI change event for its parent control or form
has occurred.
• DpiChanged, which is fired when the DPI setting changes on the display device
where the form is currently displayed.
C#
To do this, you also need to determine the operating system on which your app is running.
You can do that with code like the following:
Note that your application won't successfully detect Windows 10 if it wasn't listed as a
supported operating system in the application manifest.
You can also check the version of the .NET Framework that the application was built
against:
C#
Console.WriteLine(AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName);