在Inno Setup中将控件宽度设置为自定义页面SurfaceWidth的一半无法正常工作

问题描述

我在自定义页面上放置了一个Panel,并将其宽度设置为SurfaceWidth。然后,将其宽度更改为SurfaceWidth div 2。结果如下:

enter image description here

从屏幕截图中可以看到,新面板的宽度绝对不等于SurfaceWidth div 2。为什么会这样?

这是代码

[Setup]
WizardStyle=modern

[Code]
procedure InitializeWizard();
var
  Page: TWizardPage;
  Panel: TPanel;
begin
  Page := CreateCustomPage(wpWelcome,'Custom wizard page controls','TButton and others');
  Panel := TPanel.Create(Page);
  Panel.Width := Page.SurfaceWidth div 2;
  Panel.Left := 0;
  Panel.Height := 46;
  Panel.Anchors := [akLeft,akTop,akRight];
  Panel.Caption := 'TPanel';
  Panel.Color := clWindow;
  Panel.BevelKind := bkFlat;
  Panel.BevelOuter := bvNone; 
  Panel.ParentBackground := False;
  Panel.Parent := Page.Surface;
end;

解决方法

那是因为akRightPanel.Anchors WizardStyle中的modern(或者它暗示的是120 WizardSizePercent)。仅在InitializeWizard之后缩放向导。使用akRight,面板宽度将随向导线性增加(不成比例增加)。有解决方案,但是它们取决于您实际上希望面板在可调整大小的向导中的行为方式(modern风格也暗示)。

另请参阅Inno Setup - how to center an animated gif in resized wizard

如果要将面板的大小保持一半,则在调整向导大小时(由于WizardSizePercent而自动调整向导大小,或者由于WizardResizable而导致用户自动调整大小),请处理WizardForm.OnResize: / p>

[Code]
var
  Page: TWizardPage;
  Panel: TPanel;

procedure WizardFormResize(Sender: TObject);
begin
  Panel.Width := Page.SurfaceWidth div 2;
end;

procedure InitializeWizard();
begin
  Page := CreateCustomPage(
    wpWelcome,'Custom wizard page controls','TButton and others');
  Panel := TPanel.Create(Page);
  Panel.Width := Page.SurfaceWidth div 2;
  // ...
  WizardForm.OnResize := @WizardFormResize;
end;

确保您未设置akRight锚点。