使对话框与“大字体”兼容。

发布于 2024-08-27 13:53:04 字数 141 浏览 8 评论 0原文

您认为使 Windows 对话框与标准字体 (96 dpi) 和“大字体”设置 (120 dpi) 兼容以使对象不会重叠或被截断的最佳实践是什么?

顺便说一句:以防万一它是相关的,我有兴趣为 Delphi 对话框执行此操作。

提前致谢!

Which do you think are best practices for making a windows dialog compatible both with standard fonts (96 dpi) and "large fonts" setting (120 dpi) so that objects don't overlap or get cut off?

BTW: Just in case it's relevant, I'm interested in doing this for Delphi dialogs.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

嘿看小鸭子会跑 2024-09-03 13:53:04

一般来说,应该使用布局管理器来实现这一目的。这就是它们的设计目的。

Delphi(很长时间没有使用它)没有这样的管理器,但从那时起就能够处理不同的 dpi。您必须使用组件的自动调整大小属性来确保它们具有适合显示文本的大小。为了防止组件重叠,请使用对齐和锚点属性将它们排列在表单上。最终,您必须将组件分组到容器中才能实现正确的布局。

In general one should use layout managers for this purpose. That what they are designed for.

Delphi (did not work with it for a long time) does not have such managers but is able to handle different dpi ever since. You have to use the autosize propery of the components to ensure that they have the right size for the text they display. To prevent overlapping of components arrange them on the form using the alignment and anchor properties. Eventually you have to group components in containers to achieve a proper layout.

时光沙漏 2024-09-03 13:53:04

D2007 帮助文件中有一篇非常好的文章,位于“动态调整表单大小时的注意事项”和控件”(请注意,该 URL 是帮助文件本身,而不是网页本身)。

相同名称下的相同主题可以在 D2010 帮助文件(与上述 URL 相同的警告),或在 docwiki 上。

检查 TForm.Scaled 和 TForm.ScaleBy 也是值得的(至少一点点)。

There's a pretty good article in the D2007 help file, under "Considerations When Dynamically Resizing Forms and Controls" (note that the URL is to the help file itself, and not a web page as such).

The same topic, under the same name, can be found in the D2010 help file (same caveat about the URL as above), or on the docwiki.

It also is worthwhile (at least a little bit) to examine TForm.Scaled and TForm.ScaleBy.

过去的过去 2024-09-03 13:53:04

这就是我尝试处理 Delphi VCL 像素的方式,无论 Window 的字体大小设置如何。

unit App.Screen;

interface

uses Controls;

type
  TAppScreen = class(TObject)
  private
    FDefaultPixelsPerInch: integer;
    FPixelsPerInch: integer;
    function GetPixelsPerInch: integer;
    procedure SetPixelsPerInch(const Value: integer);
  public
    procedure AfterConstruction; override;
    function DefaultPixelsPerInch: integer;
    function InAcceptableRange(const aPPI: integer): boolean;
    procedure ScaleControl(const aControl: TWinControl);
    property PixelsPerInch: integer read GetPixelsPerInch write SetPixelsPerInch;
  end;

  TAppScreenHelper = class helper for TAppScreen
  private
    class var FInstance: TAppScreen;
    class function GetInstance: TAppScreen; static;
  public
    class procedure Setup;
    class procedure TearDown;
    class property Instance: TAppScreen read GetInstance;
  end;

implementation

uses
  TypInfo, Windows, SysUtils, Forms, Graphics;

type
  TScreenEx = class(TScreen)
  published
    property PixelsPerInch;
  end;

  TScreenHelper = class helper for TScreen
  public
    procedure SetPixelsPerInch(Value: integer);
  end;

procedure TScreenHelper.SetPixelsPerInch(Value: integer);
begin
  PInteger(Integer(Self) + (Integer(GetPropInfo(TScreenEx, 'PixelsPerInch').GetProc) and $00FFFFFF))^ := Value;
end;

procedure TAppScreen.AfterConstruction;
begin
  inherited;
  FDefaultPixelsPerInch := Screen.PixelsPerInch;
  FPixelsPerInch := FDefaultPixelsPerInch;
end;

function TAppScreen.DefaultPixelsPerInch: integer;
begin
  Result := FDefaultPixelsPerInch;
end;

function TAppScreen.GetPixelsPerInch: integer;
begin
  Result := FPixelsPerInch;
end;

function TAppScreen.InAcceptableRange(const aPPI: integer): boolean;
begin
  if DefaultPixelsPerInch > aPPI then
    Result := DefaultPixelsPerInch * 0.55 < aPPI
  else if DefaultPixelsPerInch < aPPI then
    Result := DefaultPixelsPerInch * 1.55 > aPPI
  else
    Result := True;
end;

procedure TAppScreen.ScaleControl(const aControl: TWinControl);
begin
  aControl.ScaleBy(PixelsPerInch, DefaultPixelsPerInch);
end;

procedure TAppScreen.SetPixelsPerInch(const Value: integer);
begin
  FPixelsPerInch := Value;
  Screen.SetPixelsPerInch(FPixelsPerInch);
end;

class function TAppScreenHelper.GetInstance: TAppScreen;
begin
  if FInstance = nil then
    FInstance := TAppScreen.Create;
  Result := FInstance;
end;

class procedure TAppScreenHelper.Setup;
begin
  TAppScreen.Instance;
end;

class procedure TAppScreenHelper.TearDown;
begin
  FInstance.Free;
  FInstance := nil;
end;

initialization
  TAppScreen.Setup;
finalization
  TAppScreen.TearDown;
end.

请尝试以下方法来测试不同像素值的效果:

TAppScreen.Instance.PixelsPerInch := 120;
TAppScreen.Instance.PixelsPerInch := 96;
TAppScreen.Instance.PixelsPerInch := 150;

在实例化 TForm 的后代(包括 Delphi 的 VCL 对话框)之前,您应该更改 PixelsPerInch。

This is how I try to deal with Delphi VCL's pixels regardless of Window's font size setting.

unit App.Screen;

interface

uses Controls;

type
  TAppScreen = class(TObject)
  private
    FDefaultPixelsPerInch: integer;
    FPixelsPerInch: integer;
    function GetPixelsPerInch: integer;
    procedure SetPixelsPerInch(const Value: integer);
  public
    procedure AfterConstruction; override;
    function DefaultPixelsPerInch: integer;
    function InAcceptableRange(const aPPI: integer): boolean;
    procedure ScaleControl(const aControl: TWinControl);
    property PixelsPerInch: integer read GetPixelsPerInch write SetPixelsPerInch;
  end;

  TAppScreenHelper = class helper for TAppScreen
  private
    class var FInstance: TAppScreen;
    class function GetInstance: TAppScreen; static;
  public
    class procedure Setup;
    class procedure TearDown;
    class property Instance: TAppScreen read GetInstance;
  end;

implementation

uses
  TypInfo, Windows, SysUtils, Forms, Graphics;

type
  TScreenEx = class(TScreen)
  published
    property PixelsPerInch;
  end;

  TScreenHelper = class helper for TScreen
  public
    procedure SetPixelsPerInch(Value: integer);
  end;

procedure TScreenHelper.SetPixelsPerInch(Value: integer);
begin
  PInteger(Integer(Self) + (Integer(GetPropInfo(TScreenEx, 'PixelsPerInch').GetProc) and $00FFFFFF))^ := Value;
end;

procedure TAppScreen.AfterConstruction;
begin
  inherited;
  FDefaultPixelsPerInch := Screen.PixelsPerInch;
  FPixelsPerInch := FDefaultPixelsPerInch;
end;

function TAppScreen.DefaultPixelsPerInch: integer;
begin
  Result := FDefaultPixelsPerInch;
end;

function TAppScreen.GetPixelsPerInch: integer;
begin
  Result := FPixelsPerInch;
end;

function TAppScreen.InAcceptableRange(const aPPI: integer): boolean;
begin
  if DefaultPixelsPerInch > aPPI then
    Result := DefaultPixelsPerInch * 0.55 < aPPI
  else if DefaultPixelsPerInch < aPPI then
    Result := DefaultPixelsPerInch * 1.55 > aPPI
  else
    Result := True;
end;

procedure TAppScreen.ScaleControl(const aControl: TWinControl);
begin
  aControl.ScaleBy(PixelsPerInch, DefaultPixelsPerInch);
end;

procedure TAppScreen.SetPixelsPerInch(const Value: integer);
begin
  FPixelsPerInch := Value;
  Screen.SetPixelsPerInch(FPixelsPerInch);
end;

class function TAppScreenHelper.GetInstance: TAppScreen;
begin
  if FInstance = nil then
    FInstance := TAppScreen.Create;
  Result := FInstance;
end;

class procedure TAppScreenHelper.Setup;
begin
  TAppScreen.Instance;
end;

class procedure TAppScreenHelper.TearDown;
begin
  FInstance.Free;
  FInstance := nil;
end;

initialization
  TAppScreen.Setup;
finalization
  TAppScreen.TearDown;
end.

Try the following to test the effects of different pixels value:

TAppScreen.Instance.PixelsPerInch := 120;
TAppScreen.Instance.PixelsPerInch := 96;
TAppScreen.Instance.PixelsPerInch := 150;

You should change the PixelsPerInch before instantiate TForm's descendant including Delphi's VCL dialogs.

魔法唧唧 2024-09-03 13:53:04
  • 切勿将控件及其描述标签并排放置,始终将标签放在其顶部。

但除此之外呢?也许:

  • 在标签的右侧和底部留出足够的空间,以便在使用大字体时它们不会与其他控件重叠。

我从未尝试过在这种情况下使用 TLabeledEdit,也许他们会自动执行此操作?

  • Never put a control and its describing label side by side, always put the label on top of it.

But apart from that? Maybe:

  • Leave enough space to the right and bottom of labels so they will not overlap with other controls when large fonts are used.

I have never tried using TLabeledEdit in that scenario, maybe they do that automatically?

陈独秀 2024-09-03 13:53:04

据称有商业解决方案(Developer Express VCL Layout Manager)。但我不相信他们中的任何一个。我怀疑 Embarcadero 应该将此作为当前 UI 组件集 (VCL) 中的一个关键弱点来解决。

我认为第三方组件集可能是您目前最快的解决方案。它是商业性的,但不是很贵。

http://www.devexpress.com/products/VCL/ExLayoutControl/

There are purported commercial solutions (Developer Express VCL Layout Manager). But I do not trust any of them. I suspect that Embarcadero should address this as a critical weakness in the current UI component set (VCL).

I think that the third-party component set might be your fastest solution right now. It's commercial but not hugely expensive.

http://www.devexpress.com/products/VCL/ExLayoutControl/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文