问题描述
我在自定义页面上放置了一个Panel
,并将其宽度设置为SurfaceWidth
。然后,将其宽度更改为SurfaceWidth div 2
。结果如下:
从屏幕截图中可以看到,新面板的宽度绝对不等于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;
解决方法
那是因为akRight
和Panel.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
锚点。