字体大小的独立用户界面:当我切换到120 DPI时,一切都崩溃了? [英] Font-size independent UI: everything broke when I switched to 120 DPI?

查看:147
本文介绍了字体大小的独立用户界面:当我切换到120 DPI时,一切都崩溃了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在阅读有人在另一个问题中链接到的Windows Vista UI准则,他们提到你应该能够在切换到120 DPI的情况下生存下来。那么,我启动我的方便的虚拟机,我的应用程序安装,我们得到什么... AAAAGH!大量的用户界面失败!



一切都是混乱的:有些容器不够大,一些彼此相邻的控制现在全部挤在一起/散开;有些按钮不够高;我的 ListView 列不够宽... eeek。

这听起来像是一个完全不同的方法订购。我以前的基本上是使用VS2008 Windows窗体设计器来创建,我猜,基于像素的布局。我可以看到,如果我坚持使用Windows Forms,那么 FlowLayoutPanel 会有所帮助,尽管过去我发现它们非常不灵活。它们也不能解决容器(例如形式本身)不够大的问题。大概有办法做到这一点?也许这是 AutoSize 属性?



这可能也是一个迹象表明是时候跳槽到WPF了。我的印象是,它是专门为这种事情设计的。



基本问题似乎归结为这些:


  • 如果我要坚持使用Windows窗体,那么要实现独立于字体大小的布局,在用户设置字体大小,或者设置显示器到120 DPI?

  • 是否WPF在这里有显着的优势,如果是这样,你能试图说服我,这是值得的开关?有没有在.NET堆栈或一般的字体大小无关布局的一般最佳做法?


了解 Dock 属性如何在您的控件上工作,并保留 AutoSize 本身的所有内容,当你可以的时候使用 TableLayoutPanel 。如果你做了这三件事,你会得到很多Windows Forms中的WPF设计经验。精心设计的 TableLayoutPanel 将尽最大努力调整控件的大小,使它们适合窗体。与Soeren Kuklau提到的 AutoSize 控制,停靠和 AutoScaleMode 相结合,您应该可以做出一些可以很好地扩展的东西。如果没有,你的表格可能会有太多的控制;考虑将它分成标签页,浮动工具箱或其他空间。

在WPF中,因为自动调整大小控件的概念是内置的,在大多数情况下,如果您通过使用坐标对来放置WPF元素,那么您做错了。不过,你不能改变这样的事实,即在较低的分辨率下,不需要太多的120dpi的文本来填满屏幕。有时候这个问题不是你的布局,而是一个尝试把太多太多的东西放到一个小空间里。

So I was reading those Windows Vista UI guidelines someone linked to in another question, and they mentioned that you should be able to survive a switch to 120 DPI. Well, I fire up my handy VM with my app installed, and what do we get... AAAAGH!!! MASSIVE UI FAIL!

Everything's all jumbled: some containers aren't big enough for their text; some controls that were positioned "next to each other" are now all squished together/spread apart; some buttons aren't tall enough; my ListView columns aren't wide enough... eeek.

It sounds like a completely different approach is in order. My previous one was basically using the VS2008 Windows Forms designer to create, I guess, a pixel-based layout. I can see that if I were to stick with Windows Forms, FlowLayoutPanels would be helpful, although I've found them rather inflexible in the past. They also don't solve the problem where the containers (e.g. the form itself) aren't big enough; presumably there's a way to do that? Maybe that AutoSize property?

This might also be a sign that it's time to jump ship to WPF; I'm under the impression that it's specifically designed for this kind of thing.

The basic issue seems to come down to these:

  • If I were to stick with Windows Forms, what are all the tricks to achieving a font-size-independent layout that can survive the user setting his fonts large, or setting the display to 120 DPI?
  • Does WPF have significant advantages here, and if so, can you try to convince me that it's worth the switch?
  • Are there any general "best-practices" for font-size-independent layouts, either in the .NET stack or in general?

解决方案

Learn how the Anchor and Dock properties work on your controls, leave anything that can AutoSize itself alone, and use a TableLayoutPanel when you can.

If you do these three things, you'll get a lot of the WPF design experience in Windows Forms. A well-designed TableLayoutPanel will do its best to size the controls so that they fit the form properly. Combined with AutoSize controls, docking, and the AutoScaleMode mentioned by Soeren Kuklau you should be able to make something that scales well. If not, your form might just have too many controls on it; consider splitting it into tab pages, floating toolboxes, or some other space.

In WPF it's a lot easier because the concept of auto-sizing controls is built-in; in most cases if you are placing a WPF element by using a coordinate pair you are doing it wrong. Still, you can't change the fact that at lower resolutions it doesn't take much 120 dpi text to fill up the screen. Sometimes the problem is not your layout, but an attempt to put too much into a small space.

这篇关于字体大小的独立用户界面:当我切换到120 DPI时,一切都崩溃了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆