【问题标题】:DPI scaling runtime created controls having PopupMenuDPI 缩放运行时创建的控件具有 PopupMenu
【发布时间】:2021-02-10 02:05:49
【问题描述】:

我使用的是 Delphi 10.4.1 Sydney,并创建了一个简单的控件,它在运行时设置了 Parent

constructor TMyTree.Create(AOwner: TComponent);
begin
  inherited Create(Owner);
  PopupMenu := TPopupMenu.Create(Self);
end;

procedure TMyTree.ChangeScale(M, D: Integer; isDpiChange: boolean);
begin
  inherited ChangeScale(M, D, isDpiChange);
  OutputDebugString(PChar(Format('M: %d, D: %d', [M, D])));
  //The program is started at 150% DPI and DPI changed to 175% DPI
  //Debug Output: M: 168, D: 96 - ERROR! It should be M: 168, D: 144
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  fTree := TMyTree.Create(Self);
  fTree.Parent := Self;
  OutputDebugString(PChar(Format('CurrentPPI: %d', [fTree.CurrentPPI])));
  //Debug Output at 150% DPI scale: CurrentPPI: 144 - OK!
end;

问题是ChangeScale()被VCL用错误的参数调用(见代码中的cmets)。

我认为这是由于在TMyTree 构造函数中调用PopupMenu := TPopupMenu.Create(Self); 时,VCL 将树的ComponentState 设置为[csFreeNotification]

我检查了 VCL 代码,更具体地说是TControl.SetParent()。如果csFreeNotificationComponentState 中,那么ScaleForPPINOT 调用,并且在设置Parent 时我们的树视图不会缩放。

这是 VCL 中的错误,还是有其他首选方法来创建运行时控件并设置其Parent

顺便说一句,如果我在TMyTree 构造函数中使用TImageList.Create(Self),也会出现同样的问题。

【问题讨论】:

    标签: delphi dpi


    【解决方案1】:

    【讨论】:

    • 我对这些问题投了赞成票。让我们希望EMBA不会再花三年时间来修复它们。恕我直言,这是一个主要问题。
    猜你喜欢
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 2020-05-18
    • 2021-12-15
    • 2012-02-22
    相关资源
    最近更新 更多