Visual Studio 和 DPI 问题
我正在 Windows Vista 上使用 VS2008 开发 Windows 窗体应用程序。前几天我尝试在 Windows XP 上运行我的应用程序,GUI 上的所有内容都一团糟。我意识到我在 Windows Vista 上使用 120 Dpi 设置开发应用程序,而我的 XP 设置为 96 dpi。
我的应用程序有多个 UserControl,如果我将 DPI 更改为 96,即使在 Visual Studio 本身中,它们也会缩小。我确信现在很多人都在高 DPI 下使用 Visual Studio。那么如何确保我的 GUI 在 Visual Studio 和运行时都不会混乱呢?
编辑:我已经阅读了有关此问题的几篇文章,并且了解到我应该将 AutoScaleMode 设置为 None。但是,这仍然不会阻止我的标签适应操作系统强制执行的新 DPI 设置。我需要一种方法来防止标签增大/缩小,因为其他 GUI 元素具有固定大小。
I am developing a Windows Forms application using VS2008 on Windows Vista. I tried to run my application on Windows XP the other day, and everything on GUI was messed up. I realized that I developed the application using 120 Dpi setting on Windows Vista and my XP was set to 96 dpi.
My application has several UserControls and all of them shrinks even in the Visual Studio itself if I change my DPI to 96. I am sure a lot of people are using Visual Studio in high DPIs these days. So how can make sure that my GUI does not get messed up both in Visual Studio and runtime?
EDIT: I have read couple articles on this issue and I learned that I should be setting AutoScaleMode to None. However, this still does not prevent my labels to adapt new DPI settings enforced by the operating system. I need a way to prevent my labels to grow/shrink because other GUI elements have fix sizes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自从我处理这个问题以来已经有一段时间了,但尝试设置 AutoSize = False。此外,UseCompatibleTextRendering = True 可能会有所帮助。
It has been a while since I worked on this issue, but try setting AutoSize = False. In addition, UseCompatibleTextRendering = True might help.
这是一个相当老的问题,但我想分享我的解决方案/意见。我最近遇到了类似的问题。实际上,我希望 Visual Studio 保持我的 WinForms 不变,但它们可以在运行时扩展。我发现没有关于如何正确做到这一点的一致总结。经过一些阅读和实验后,我得出了这个解决方案:
Font = MS Sans; 11px
InitializeComponent
之后,设置:Font = SystemFonts.DefaultFont
SetProcessDPIAwareness
由于 AutoScaleMode 保持活动状态,所有改变 DPI 的魔法都会起作用,甚至每个显示器的 DPI 感知也是如此。剩下的是以缩放效果良好的方式设计表单。
我在我的博客上写了详细信息:http://www.sgrottel.de/? p=1581&lang=zh
This is a rather old question, but I want to share my solution/opinion. I ran into a similar problem recently. Actually, I want Visual Studio to keep my WinForms as they are, but them to scale at runtime. I found no consistent summary on how to correctly do that. After some reading and experimenting I came to this solution:
AutoScaleMode = Font
.Font = MS Sans; 11px
InitializeComponent
, set:Font = SystemFonts.DefaultFont
SetProcessDPIAwareness
Since AutoScaleMode remains active, all DPI-changing magic works, even per-monitor DPI awareness. What remains, is designing Forms in a way scaling works nicely.
I wrote the details on my Blog: http://www.sgrottel.de/?p=1581&lang=en