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

查看:333
本文介绍了当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 Common Controls的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.

我建议您不要使用TForm.Scaled = true(这是Delphi中的默认值,除非您已修改它,大部分表单都具有Scaled = true )与使用内置delphi窗体设计器构建的VCL应用程序的高DPI Aware标志(如David的答案所示)。

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为true时,您可以期待看到的破坏类型的最小样本,以及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缩放设置为200%的字体时,Windows 7和8中的Delphi XE2类似地出现错误,但是这些故障似乎与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 data-explorer控件是围绕标准Windows Tree常用控件的C#WinForms包装器。这是一个纯粹的微软故障,修复它可能要求Embarcadero为他们的数据浏览器重写一个纯的本机.Net树控件,或者编写一些DPI检查和修改属性代码来改变控件中的项目高度。甚至微软的WinForms也不会自动地处理高DPI,而且不需要自定义的kludge代码。

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.

更新:有趣的factoid:虽然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,我会提出一个两阶段的计划。第一阶段是清点我的代码,以便为高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.

更新: strong> 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天全站免登陆