Setting control width to half of custom page SurfaceWidth does not work correctly in Inno Setup

隐身守侯 提交于 2021-02-18 19:09:10

问题


I placed a Panel on my custom page and gave it a width of SurfaceWidth. Then I changed its width to SurfaceWidth div 2. Here's the result:

As you can see from the screenshot the new panel's width is definitely not equal to SurfaceWidth div 2. Why is that so?

Here's the code:

[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;

回答1:


That's because of the akRight in Panel.Anchors and modern WizardStyle (or rather the 120 WizardSizePercent it implies). The wizard is scaled only after the InitializeWizard. With akRight, the panel width will grow linearly (not proportionally) with the wizard. There are solutions, but they depend on how you actually want the panel to behave in the resizable wizard (also implied by the modern style).

See also Inno Setup - how to center an animated gif in resized wizard.

If you want to keep the panel at half size, when the wizard is resized (either automatically due to WizardSizePercent or by the user due to WizardResizable), handle 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;

Make sure you do not set the akRight anchor.



来源:https://stackoverflow.com/questions/64695256/setting-control-width-to-half-of-custom-page-surfacewidth-does-not-work-correctl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!