[英]Windows High DPI Scaling for WinForm
This is something I had a lot of trouble with.这是我遇到很多麻烦的事情。 After days of experimenting, I finally figured out how to properly scale WinForms.经过几天的试验,我终于想出了如何正确缩放 WinForms。 This might help some other folks too.这也可能对其他人有所帮助。
There are a lot of recommendations of modefying the app.manifest or app.config files.有很多关于修改 app.manifest 或 app.config 文件的建议。 The solution might have worked with earlier versions of Windows, but none worked for me.该解决方案可能适用于早期版本的 Windows,但没有一个对我有用。 After installing my application, pictures and controls got messed up (in Visual Studio debugging it all worked).安装我的应用程序后,图片和控件搞砸了(在 Visual Studio 中调试一切正常)。 After some testing, I had seen that changing the "overwrite high dpi scaling" option setting to "application" worked for me.经过一些测试,我发现将“覆盖高 dpi 缩放”选项设置更改为“应用程序”对我有用。 But I wanted to support this right within the app and not modifying some Windows settings.但我想在应用程序中支持这一点,而不是修改某些 Windows 设置。
I stumbled across a Windows support document explaining, that they have changed some DPI scaling with the latest release of Windows and old methods might not work.我偶然发现了一份 Windows 支持文档,解释说他们已经使用最新版本的 Windows 更改了一些 DPI 缩放比例,而旧方法可能无法正常工作。
All you actually have to do is following these steps:您实际要做的就是按照以下步骤操作:
</startup>
and <userSettings>
, insert the following snippet在</startup>
和<userSettings>
,插入以下代码段<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
Application.EnableVisualStyles()
That's it!就是这样! Your app should be looking great in 4K environment after installing on a machine.在机器上安装后,您的应用程序在 4K 环境中应该看起来很棒。 For further reference, please see this article from Microsoft.如需进一步参考,请参阅Microsoft 的这篇文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.