当 Windows 字体缩放大于 100% 时,如何使我的 GUI 表现良好 [英] How do I make my GUI behave well when Windows font scaling is greater than 100%

查看:36
本文介绍了当 Windows 字体缩放大于 100% 时,如何使我的 GUI 表现良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 控制面板中选择大字体大小(如 125% 或 150%)时,VCL 应用程序会出现问题,每次设置像素级时都会出现问题.

When choosing large font sizes in the Windows control panel (like 125%, or 150%) then there are problems in a VCL application, every time something has been set pixelwise.

TStatusBar.Panel 为例.我已经设置了它的宽度,以便它只包含一个标签,现在使用大字体标签溢出".其他组件也有同样的问题.

Take the TStatusBar.Panel. I have set its width so that it contains exactly one label, now with big fonts the label "overflows". Same problem with other components.

戴尔的一些新笔记本电脑已经将 125% 作为默认设置,因此虽然过去这个问题很少见,但现在非常重要.

Some new laptops from Dell ship already with 125% as default setting, so while in the past this problem was quite rare now it is really important.

可以做些什么来克服这个问题?

What can be done to overcome this problem?

推荐答案

注意:请参阅其他答案,因为它们包含非常有价值的技巧.我在这里的回答只提供了警告和警告,不要假设 DPI 意识很容易.

Note: Please see the other answers as they contain very valuable techniques. My answer here only provides caveats and cautions against assuming DPI-awareness is easy.

我通常避免使用 TForm.Scaled = True 进行 DPI 感知缩放.只有当 DPI 意识对打电话给我并愿意为此付费的客户变得重要时,它才对我很重要.这种观点背后的技术原因是 DPI 意识与否,你正在打开一扇通往伤害世界的窗口.许多标准和第三方 VCL 控件在高 DPI 中无法正常工作.一个显着的例外是包装 Windows 通用控件的 VCL 部件在高 DPI 下工作得非常好.大量第三方和内置 Delphi VCL 自定义控件在高 DPI 下无法正常工作,或者根本无法正常工作.如果您打算启用 TForm.Scaled,请务必在 96、125 和 150 DPI 下对项目中的每个表单以及您使用的每个第三方和内置控件进行测试.

I generally avoid DPI-aware scaling with TForm.Scaled = True. DPI awareness is only important to me when it becomes important to customers who call me and are willing to pay for it. The technical reason behind that point of view is that DPI-awareness or not, you are opening a window into a world of hurt. Many standard and third party VCL controls do not work well in High DPI. The notable exception that the VCL parts that wrap Windows Common Controls work remarkably well at high DPI. A huge number of third party and built-in Delphi VCL custom controls do not work well, or at all, at high DPI. If you plan to turn on TForm.Scaled be sure to test at 96, 125, and 150 DPI for every single form in your project, and every single third party and built in control that you use.

Delphi 本身是用 Delphi 编写的.对于大多数表单,它都打开了高 DPI 感知标志,尽管最近在 Delphi XE2 中,IDE 作者自己决定不打开高 DPI 感知清单标志.请注意,在 Delphi XE4 及更高版本中,开启了 HIGH DPI 感知标志,IDE 看起来不错.

Delphi itself is written in Delphi. It has the High DPI awareness flag turned on, for most forms, although even as recently as in Delphi XE2, the IDE authors themselves decided NOT to turn that High DPI Awareness manifest flag on. Note that in Delphi XE4 and later, the HIGH DPI awareness flag is turned on, and the IDE looks good.

我建议您不要使用带有高 DPI 感知标志的 TForm.Scaled=true(这是 Delphi 中的默认设置,因此除非您对其进行了修改,否则您的大多数表单都具有 Scaled=true)(如 David 的答案)使用内置的 delphi 表单设计器构建的 VCL 应用程序.

I suggest that you do not use TForm.Scaled=true (which is a default in Delphi so unless you've modified it, most of your forms have Scaled=true) with the High DPI Aware flags (as shown in David's answers) with VCL applications that are built using the built-in delphi form designer.

我过去曾尝试制作一个最小样本,说明当 TForm.Scaled 为真时,以及当 Delphi 表单缩放出现故障时,您可以期望看到的那种损坏.这些故障并不总是并且仅由 96 以外的 DPI 值触发.我一直无法确定其他事情的完整列表,其中包括 Windows XP 字体大小更改.但由于这些故障大多只出现在我自己的应用程序中,在相当复杂的情况下,我决定向您展示一些您可以验证的证据.

I have tried in the past to make a minimal sample of the kind of breakage you can expect to see when TForm.Scaled is true, and when Delphi form scaling has a glitch. These glitches are not always and only triggered by a DPI value other than 96. I have been unable to determine a complete list of other things, that includes Windows XP font size changes. But since most of these glitches appear only in my own applications, in fairly complex situations, I have decided to show you some evidence you can verify yourselves.

Delphi XE 在 Windows 7 中将 DPI Scaling 设置为Fonts @ 200%"时看起来像这样,Delphi XE2 在 Windows 7 和 8 上同样被破坏,但这些故障似乎从 Delphi XE4 开始得到修复:

Delphi XE looks like this when you set the DPI Scaling to "Fonts @ 200%" in Windows 7, and Delphi XE2 is similarly broken on Windows 7 and 8, but these glitches appear to be fixed as of Delphi XE4:

这些大多是标准 VCL 控件,它们在高 DPI 下表现不佳.请注意,大多数事情根本没有进行缩放,因此 Delphi IDE 开发人员决定忽略 DPI 意识,并关闭 DPI 虚拟化.这么有趣的选择.

These are mostly Standard VCL controls that are misbehaving at high DPI. Note that most things have not been scaled at all, so the Delphi IDE developers have decided to ignore the DPI awareness, as well as turning off the DPI virtualization. Such an interesting choice.

只有在想要这种新的痛苦和困难选择的额外来源时才关闭 DPI 虚拟化.我建议你别管它.请注意,Windows 通用控件似乎大多工作正常.请注意,Delphi 数据浏览器控件是围绕标准 Windows 树公共控件的 C# WinForms 包装器.这是一个纯粹的微软故障,修复它可能需要 Embarcadero 为他们的数据浏览器重写一个纯原生 .Net 树控件,或者编写一些 DPI-check-and-modify-properties 代码来更改控件中的项目高度.即使是微软的 WinForms 也无法干净、自动地处理高 DPI,而且无需自定义混合代码.

Turn off DPI virtualization only if want this new additional source of pain, and difficult choices. I suggest you leave it alone. Note that Windows common controls mostly seem to work fine. Note that the Delphi data-explorer control is a C# WinForms wrapper around a standard Windows Tree common control. That's a pure microsoft glitch, and fixing it might either require Embarcadero to rewrite a pure native .Net tree control for their data explorer, or to write some DPI-check-and-modify-properties code to change item heights in the control. Not even microsoft WinForms can handle high DPI cleanly, automatically and without custom kludge code.

更新:有趣的事实:虽然 delphi IDE 似乎没有虚拟化",但它没有使用 David 显示的清单内容来实现非 DPI 虚拟化".也许它在运行时使用了一些 API 函数.

Update: Interesting factoid: While the delphi IDE appears not to be "virtualized", it is not using the manifest content shown by David to achieve "non-DPI-virtualization". Perhaps it is using some API function at runtime.

更新 2:针对我将如何支持 100%/125% DPI,我将提出一个两阶段计划.第 1 阶段是为需要修复高 DPI 的自定义控件清点我的代码,然后制定修复它们或逐步淘汰它们的计划.第 2 阶段是将我的代码中的一些区域设计为没有布局管理的表单,并将它们更改为使用某种布局管理的表单,以便 DPI 或字体高度更改可以在不裁剪的情况下工作.我怀疑在大多数应用程序中,这种内部控制"布局工作要比内部控制"工作复杂得多.

Update 2: In response to how I would support 100%/125% DPI, I would come up with a two-phase plan. Phase 1 is to inventory my code for custom controls that need to be fixed for high DPI, and then make a plan to fix them or phase them out. Phase 2 would be to take some areas of my code which are designed as forms without layout management and change them over to forms that use some kind of layout management so that DPI or font height changes can work without clipping. I suspect that this "inter-control" layout work would be far more complex in most applications than the "intra-control" work.

更新: 2016 年,最新的 Delphi 10.1 Berlin 在我的 150 dpi 工作站上运行良好.

Update: In 2016, the latest Delphi 10.1 Berlin is working well on my 150 dpi workstation.

这篇关于当 Windows 字体缩放大于 100% 时,如何使我的 GUI 表现良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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