解决VS在高DPI下设计出的Winform程序界面变形问题

在目前高分屏流行的情况下,windows缩放与布局仍然设置为100%就显得太小(特别是笔记本),通常会调整为125%或150%,

VS在缩放与布局设置为非100%的时候,就会自动启动DPI感知模式,以防止VS界面模糊。

但也会导致一个问题

就是在高DPI下(非100%缩放与布局)设计的winform程序

当拿到不同的缩放条件下运行时就会遇到界面变形或不一致的问题,

我们这里提供了一个解决方案来防止高DPI下设计出的winform程序界面变形(但是不能解决winform程序在高DPI下可能变糊)

即禁用VS的高DPI感知模式,让VS运行在标准DPI环境下,这样设计出来的程序无论在何种DPI环境下都不会产生变形(但可能模糊,我们这里主要解决变形问题)

原因:

With the extreme differences in display DPIs, especially in modern 2-in-1 devices, this can still happen with the most current versions of the .NET Framework and Visual Studio. To address this in a team using different DPI displays, make sure Visual Studio always starts in a non-DPI-aware mode, so the Windows Forms designer always bases the layout calculation on 96 DPI. To this end, simply set the following registry key to disable Visual Studio's HighDPI awareness

由于显示DPI的极端差异,尤其是在现代2合1设备中,这种情况在最新版本的.NET Framework和Visual Studio中仍可能发生。 要在使用不同DPI显示的团队中解决此问题,请确保Visual Studio始终以非DPI感知模式启动,因此Windows窗体设计器始终将布局计算的基础设置为96 DPI。 为此,只需设置以下注册表项即可禁用Visual Studio的HighDPI意识:

解决方法:

1、手动在注册表中添加项

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsdevenv.exe]

"dpiAwareness"=dword:00000000

2、Bat一键处理(新建文本文件.txt 改后缀为 bat,将下面代码粘贴到文本文件里保存,双击执行即可)

reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsdevenv.exe" /v "dpiAwareness" /t REG_DWORD /d "0"

Last modification:February 4th, 2020 at 11:48 am
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment