与字体大小无关的 UI:当我切换到 120 DPI 时一切都坏了? [英] Font-size independent UI: everything broke when I switched to 120 DPI?

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

问题描述

所以我正在阅读某人在另一个问题中链接的那些 Windows Vista UI 指南,他们提到您应该能够在切换到 120 DPI 后幸存下来.好吧,我在安装了应用程序的情况下启动了我方便的 VM,然后我们会得到什么... AAAAGH !!!大量用户界面失败!

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!

一切都乱七八糟:有些容器不足以容纳它们的文本;一些彼此相邻"的控件现在都被挤压在一起/分开;有些按钮不够高;我的 ListView 列不够宽... eeek.

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.

听起来应该采用完全不同的方法.我的前一个基本上是使用 VS2008 Windows 窗体设计器来创建基于像素的布局.我可以看到,如果我坚持使用 Windows 窗体,FlowLayoutPanels 会有所帮助,尽管我过去发现它们相当不灵活.它们也没有解决容器(例如表单本身)不够大的问题;大概有办法做到这一点?也许那个 AutoSize 属性?

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?

这也可能表明是时候跳槽到 WPF 了;我的印象是它是专门为这种事情设计的.

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:

  • 如果我坚持使用 Windows 窗体,有什么技巧可以实现与字体大小无关的布局,使用户可以将其字体设置为大,或将显示设置为 120 DPI?
  • WPF 在这方面是否具有显着优势?如果是,您能否说服我值得转换?
  • 在 .NET 堆栈中或一般情况下,是否有适用于字体大小无关布局的通用最佳实践"?

推荐答案

了解 AnchorDock 属性如何在您的控件上工作,留下任何可以AutoSize 本身,并尽可能使用 TableLayoutPanel.

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.

如果您做到这三件事,您将在 Windows 窗体中获得很多 WPF 设计体验.一个设计良好的 TableLayoutPanel 将尽最大努力调整控件的大小,使其适合表单.结合 AutoSize 控件、停靠和 Soeren Kuklau 提到的 AutoScaleMode,您应该能够制作出可很好缩放的东西.如果没有,您的表单可能有太多控件;考虑将其拆分为标签页、浮动工具箱或其他一些空间.

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.

在 WPF 中,这要容易得多,因为内置了自动调整大小控件的概念;在大多数情况下,如果您使用坐标对放置 WPF 元素,则您做错了.尽管如此,您仍无法改变这样一个事实,即在较低分辨率下,不需要太多 120 dpi 的文本即可填满屏幕.有时问题不在于你的布局,而在于试图在一个小空间里放太多东西.

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.

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

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