我怎样才能让我的WinForms应用程序DPI感知 [英] How can i Make my WinForms Application DPI-Aware

查看:609
本文介绍了我怎样才能让我的WinForms应用程序DPI感知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那有一个WinForms应用程序作为我们的主打产品的公司工作。
最近我们重新设计了品牌和用户界面。我们注意到,窗体现在不正确显示文本和一些控制是失准或已消失了的边缘。

I'm working in a company that has a Winforms application as our flagship product. we recently reworked the branding and UI. We have noticed that the Forms now do not display the text properly and some controls are out of alignment or have disappeared off the edge.

是否有可能为我做的这个应用程序DPI感知与因为我们没有时间再保理业务量最少的形式。

Is it possible for me to make the forms on this application DPI-Aware with the least amount of re-factoring as we don't have time.

推荐答案

这是至关重要的你不指定像素坐标和大小。这排除了使用 Control.Top Control.Left ,这是设计师做什么,当你只是地方表单上的控件。

It's essential that you don't specify pixel coordinates and sizes. This rules out using Control.Top and Control.Left, which is what the designer does, when you "just place" the controls on a form.

要获取不同的DPI设置工作的UI,几乎一切都必须动态调整。这些控件应该有 Control.AutoSize 启用。但是,仅仅让自动调整大小将完全搞砸了你的布局,因为仓位的控制仍然是静态的。

To get an UI that works with different DPI settings, pretty much everything has to be dynamically sized. The controls should have Control.AutoSize enabled. But just enabling AutoSize would totally screw up your layout, since the control position would still be static.

要获得动态定位的控制,你可以使用容器控件,如 FlowLayoutPanel的 TableLayoutPanel中 (设置为自动调整大小尺寸)。那么这些内的正常对照组将只是移动角落找寻形式,根据自动确定大小。

To get dynamically position the controls, you can use container controls, like the FlowLayoutPanel and the TableLayoutPanel (with sizes set to AutoSize). The normal controls inside of those would then just move arround the form, according to automatically determined sizes.

如你所见,这并不简单,需要一点经验得到它的权利,需要一个庞大的检测量(用不同的DPI设置的虚拟机工作的伟大)。但我认为这绝对应该做的,因为我总是生气,如果事情看起来愚蠢和马车在我的笔记本电脑。

As you can see, this isn't simple, requires a bit of experience to get it right and needs a huge amount of testing (virtual machines with different DPI settings work great). But I think it should definitely be done, since I'm always annoyed if something looks stupid and buggy on my laptop.

这篇关于我怎样才能让我的WinForms应用程序DPI感知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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