显示 PPI 缩放处于活动状态时如何正确使用 TGridPanel?

How to correctly use TGridPanel when display PPI scaling is active?

我编写了一个小的测试 VCL 应用程序,其监视器 PPI 为 96。

该应用程序有一个 TGridPanel,它有一个绝对像素大小的列。

在那一列上,我放置了一个 TComboBox 并将其对齐 alClient

这是 DFM 代码:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 182
  ClientWidth = 514
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object GridPanel1: TGridPanel
    Left = 0
    Top = 0
    Width = 514
    Height = 182
    Align = alClient
    Caption = 'GridPanel1'
    ColumnCollection = <
      item
        Value = 100.000000000000000000
      end
      item
        SizeStyle = ssAbsolute
        Value = 150.000000000000000000
      end>
    ControlCollection = <
      item
        Column = 0
        Control = Button1
        Row = 0
      end
      item
        Column = 1
        Control = ComboBox1
        Row = 0
      end
      item
        Column = 0
        Control = Edit1
        Row = 1
      end>
    RowCollection = <
      item
        Value = 50.000000000000000000
      end
      item
        Value = 50.000000000000000000
      end>
    TabOrder = 0
    object Button1: TButton
      Left = 1
      Top = 1
      Width = 362
      Height = 21
      Align = alTop
      Caption = 'Button1'
      TabOrder = 0
      OnClick = Button1Click
    end
    object ComboBox1: TComboBox
      Left = 363
      Top = 1
      Width = 150
      Height = 21
      Align = alClient
      TabOrder = 1
      Text = 'ComboBox1'
    end
    object Edit1: TEdit
      Left = 1
      Top = 91
      Width = 362
      Height = 21
      Align = alTop
      TabOrder = 2
      Text = 'Edit1'
    end
  end
end

和 PAS 代码:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    GridPanel1: TGridPanel;
    Button1: TButton;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  PPI: Integer;
begin
  PPI := Integer.Parse(Edit1.Text);
  GridPanel1.ScaleForPPI(PPI);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Edit1.Text := Screen.PixelsPerInch.ToString;
end;

end.

然后我在高级缩放设置中 Windows10 中将自定义缩放因子更改为 125。

在我再次 运行 应用程序时注销并再次登录后,组合框的下拉按钮不再可见。

你是怎么处理这个问题的?

我尝试调用 GridPanel1.ScaleForPPI(96) 来恢复组合框上的下拉按钮。不过,这种做法违背了 PPI 缩放的目的,不是吗?

问题在 Delphi 10.3.1.

中消失了

所以这至少是 Delphi 10.1(以及其他可能的旧版本)中的错误。