EnableWindowsFormsHighDpiAutoResizing 设置在 C# .NET windows 窗体应用程序中有什么作用?

Way*_*oda 6 c# winforms

我正在尝试使用 C# .NET 和常规 Windows 窗体(不是 WPF)制作每个监视器 DPI 感知应用程序。

我理解选择加入每台显示器 DPI 支持的概念,并在清单中做到了这一点:

<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
   DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need 
   to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should 
   also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->

<application xmlns="urn:schemas-microsoft-com:asm.v3">
  <windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
  </windowsSettings>
</application>
Run Code Online (Sandbox Code Playgroud)

当我选择这样做时,当我的应用程序从 96DPI 监视器(我的默认监视器)拖到 144DPI 监视器上时,它的像素大小根本不会改变(即应用程序在两个监视器上的像素对像素都是相同的,除了最小化-最大化-关闭字形的细微差别)。因此应用程序非常小,文本在 144DPI 显示器上很难阅读。

似乎该EnableWindowsFormsHighDpiAutoResizing设置无效,因为我的应用程序以完全相同的方式显示此设置是真还是假,除非我在 app.config 文件中做错了什么:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
  </appSettings>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
  </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

任何人都可以阐明此选项的作用吗?

它是否是编写 C# windows 窗体应用程序的解决方案的一部分,该应用程序在从 96DPI 监视器拖动到 144DPI 监视器时会自动调整自身大小?(我的意思是自动,无需我编写代码来迭代所有控件并设置自定义比例因子)。

我已经对这个问题进行了很多小时的研究,但我自己还没有明确的答案。

看来,如果我选择加入每个显示器DPI意识那么我必须hanldle了WM_DPICHANGED自己为了做点事情。如果这是答案,那就这样吧,但我真的觉得我错过了一些内置的做事方式。

小智 1

“dpiAware = true”表示应用程序应处理 DPI 更改,否则 Windows 操作系统将为您缩放表单/字体。这是我的理解。