我希望用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>
当我选择该选项时,我的应用程序在从一个96DPI的显示器(我的默认显示器)拖到一个144DPI的显示器上时,其像素大小根本不会改变(即应用程序在两个显示器上都是像素对像素相同的,除了最小化、最大化、关闭图形略有不同)。因此,在144DPI的显示器上,应用程序非常小,文本很难阅读。
似乎“EnableWindowsFormsHighDpiAutoResizing”设置没有效果,我的应用程序显示方式完全相同,无论这个设置是true还是false,除非我在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>
有人能解释一下这个选项是做什么用的吗?
它是否是编写C# Windows窗体应用程序的解决方案的一部分,可以在从96DPI监视器拖动到144DPI监视器时自动调整大小? (自动意味着无需编写代码来迭代所有控件并设置自定义比例因子)。
我已经花了很多时间研究这个问题,但我自己还没有清楚的答案。
似乎如果我选择进入每个监视器的DPI感知,则< strong>必须自己处理< code> WM_DPICHANGED 才能执行某些操作。如果这是答案,那就是了,但我真的觉得自己错过了一些内置的方法。