将控件宽度设置为自定义页面 SurfaceWidth 的一半在 Inno Setup 中无法正常工作
Setting control width to half of custom page SurfaceWidth does not work correctly in Inno Setup
我在我的自定义页面上放置了一个 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;
那是因为 Panel.Anchors
中的 akRight
和 modern
WizardStyle
(or rather the 120 WizardSizePercent
暗示的)。向导仅在 InitializeWizard
之后缩放。使用 akRight
,面板宽度将随向导线性增长(不成比例)。有解决方案,但它们取决于您实际希望面板在可调整大小向导中的行为方式(也由 modern
样式暗示)。
另见 。
如果您想将面板保持一半大小,则在调整向导大小时(由于 WizardSizePercent
自动调整或由于 WizardResizable
由用户调整),处理 WizardForm.OnResize
:
[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
锚点。
我在我的自定义页面上放置了一个 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;
那是因为 Panel.Anchors
中的 akRight
和 modern
WizardStyle
(or rather the 120 WizardSizePercent
暗示的)。向导仅在 InitializeWizard
之后缩放。使用 akRight
,面板宽度将随向导线性增长(不成比例)。有解决方案,但它们取决于您实际希望面板在可调整大小向导中的行为方式(也由 modern
样式暗示)。
另见
如果您想将面板保持一半大小,则在调整向导大小时(由于 WizardSizePercent
自动调整或由于 WizardResizable
由用户调整),处理 WizardForm.OnResize
:
[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
锚点。