Inno Setup 相对于现有按钮定位自定义按​​钮

Inno Setup position a custom button relative to existing buttons

我知道可以在任何页面上创建自定义按钮并使用以下代码使用绝对值定位它:

//Create the About button
  AboutButton := TButton.Create(WizardForm);
  AboutButton.Caption := '&About';
  AboutButton.Width := ScaleX(75);
  AboutButton.Height := ScaleY(23);
  AboutButton.Left := WizardForm.InfoAfterPage.Left + 10;
  AboutButton.Top := WizardForm.InfoAfterPage.Height + 90;
  AboutButton.OnClick := @AboutButtonClick;
  AboutButton.Parent := WizardForm.NextButton.Parent;

唯一的问题是,由于它使用绝对值进行定位,如果用户打开了 Windows 缩放(在“屏幕分辨率”>“使文本和其他项目变大或变小”下)并设置了缩放调到中等 125%,按钮就会与其他内置按钮不对齐,从而导致一团糟。因此,有没有办法根据内置按钮定位任何新创建的自定义按钮,以便它们始终按预期显示在行中?或者对于我忽略的这种缩放困境是否有另一种解决方案?

对所有 positions/dimensions 使用 ScaleX()ScaleY()

  AboutButton.Width := ScaleX(75);
  AboutButton.Height := ScaleY(23);
  AboutButton.Left := ScaleX(WizardForm.InfoAfterPage.Left + 10);
  AboutButton.Top := ScaleY(WizardForm.InfoAfterPage.Height + 90);

这应该适用于所有 DPI。

我会这样写:

  AboutButton := TButton.Create(WizardForm);
  AboutButton.Caption := '&About';
  AboutButton.Left := WizardForm.InfoAfterPage.Left + (WizardForm.ClientWidth - 
   (WizardForm.CancelButton.Left + WizardForm.CancelButton.Width)); 
   // sets Left position from the Page Left 
   // + already scaled gap calculated on the basis of TLama's recommendations
  AboutButton.Width := WizardForm.NextButton.Width;   
   // sets same Width as NextButton
  AboutButton.Top := WizardForm.NextButton.Top;       
   // sets same Top position as NextButton
  AboutButton.Height := WizardForm.NextButton.Height; 
   // sets same Height as NextButton
  AboutButton.OnClick := @AboutButtonClick;
  AboutButton.Parent := WizardForm.NextButton.Parent;

示例:

96 (Default)

120 (125%)

144 (150%)