在不同 DPI 设置下运行的 Windows 窗体应用程序中的奇怪行为
我有一个带有一个主窗体的 Windows 窗体应用程序(针对 .NET Framework 3.5 用 vs2010/C# 编写)。它是在 Win7 的 100% DPI 设置下设计的(我相信是 96 dpi)。当将计算机切换到 150% 时,一切看起来都缩放得很好并且所有比例都保持不变。
然而,当我切换到 125% 时,某些控件突然无法缩放,并且看起来与 100% 时一样大。这会弄乱整个布局,并向用户隐藏一些控件。
对于 125% 和 150% 设置之间的巨大行为差异,是否有任何逻辑解释?
另外,有没有更快的方法来测试这个?每次切换时都必须注销并重新登录,这很快就会变得烦人。
I have a Windows Forms application (written in vs2010/C# against .NET framework 3.5) with one main form. It was designed at Win7's 100% DPI setting (I believe that's 96 dpi). When switching the computer to 150%, everything appears to scale just fine and all proportions are kept.
However, when I switch to 125%, some of the controls suddenly don't scale and appear to be as big as they would be at 100%. This messes up the whole layout, and hides some controls from the user.
Is there any kind of logical explanation as to the large difference in behavior between the 125% and 150% settings?
Also, is there a quicker way to test this? Having to log off and back in again every time I switch is quickly becoming annoying.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于你所观察到的现象没有简单的解释。
无需经历痛苦的登录周期即可进行测试的一种廉价方法是在 OnLoad 方法中更改表单的 Font 属性:
There's no simple explanation for what you observe.
A cheap way to test this without having to go through the painful login cycle is to change the form's Font property in the OnLoad method:
查看表单的 AutoScaleMode。它可能设置为 Font 或 Dpi
Look at form's AutoScaleMode. It is probably set to Font or Dpi
添加到 John Arlen 的帖子:
您可能还希望使用 自动尺寸模式。
Add to John Arlen's post:
You may also want to allow the form to Grow and Shrink, using the AutoSizeMode.
关于“另外,有没有更快的方法来测试这个?每次切换时都必须注销并重新登录,这很快就会变得烦人。”
最好的办法是使用具有不同 DPI 设置的虚拟机。
您只需从“真实”机器运行您的应用程序即可。
With respect to "Also, is there a quicker way to test this? Having to log off and back in again every time I switch is quickly becoming annoying."
Best thing is to use a Virtual Machine with a different DPI settings.
You just run your application from the 'real' machine.