TInputDirWizardPage带有单选按钮

3
我需要一个设置页面,其中包含两个单选按钮。点击第二个按钮应该启用一个输入框来定义路径(就像在TInputDirWizardPage中所做的那样)。
是否可以根据我的需求自定义TInputDirWizardPage
还是我需要构建一个CustomPage并自己定义控件?如果第二个问题的答案是肯定的,那么我如何能够使用“目录输入”(来自TInputDirWizardPage),或者也需要自己构建它?
1个回答

2

正如您所猜测的那样,您有几个选项:

  1. TWizardPage 开始,从头开始构建一切
  2. TInputDirWizardPage 开始,并添加单选按钮
  3. TInputOptionWizardPage 开始,并添加编辑框

第二个选项可能涉及最少的自定义。虽然它需要从 Is it possible to allow a user to skip a TInputDirWizardPage in Inno Setup? 进行修改。

{ WORKAROUND }
{ Checkboxes and Radio buttons created on runtime do }
{ not scale their height automatically. }
{ See https://stackoverflow.com/q/30469660/850848 }
procedure ScaleFixedHeightControl(Control: TButtonControl);
begin
  Control.Height := ScaleY(Control.Height);
end;

var
  Page: TInputDirWizardPage;
  DefaultLocationButton: TRadioButton;
  CustomLocationButton: TRadioButton;
  OldNextButtonOnClick: TNotifyEvent;

procedure LocationButtonClick(Sender: TObject);
begin
  Page.Edits[0].Enabled := CustomLocationButton.Checked;
  Page.Buttons[0].Enabled := CustomLocationButton.Checked;
end;

procedure NextButtonOnClick(Sender: TObject);
var
  PrevDir: string;
begin
  { Do not validate, when "default location" is selected }
  if (WizardForm.CurPageID = Page.ID) and DefaultLocationButton.Checked then
  begin
    PrevDir := Page.Values[0];
    Page.Values[0] := GetWinDir; { Force value to pass validation }
    OldNextButtonOnClick(Sender);
    Page.Values[0] := PrevDir;
  end
    else
  begin
    OldNextButtonOnClick(Sender);
  end;
end;

procedure InitializeWizard();
begin
  Page := CreateInputDirPage(
    wpWelcome,
    'Select Personal Data Location', 'Where should personal data files be stored?',
    '', False, 'New Folder');
  Page.Add('');

  DefaultLocationButton := TRadioButton.Create(WizardForm);
  DefaultLocationButton.Parent := Page.Surface;
  DefaultLocationButton.Top := Page.Edits[0].Top;
  DefaultLocationButton.Caption := 'Use default location';
  DefaultLocationButton.Checked := True;
  DefaultLocationButton.OnClick := @LocationButtonClick;
  ScaleFixedHeightControl(DefaultLocationButton);
  
  CustomLocationButton := TRadioButton.Create(WizardForm);
  CustomLocationButton.Parent := Page.Surface;
  CustomLocationButton.Top :=
    DefaultLocationButton.Top + DefaultLocationButton.Height + ScaleY(8);
  CustomLocationButton.Caption := 'Use custom location';
  CustomLocationButton.OnClick := @LocationButtonClick;
  ScaleFixedHeightControl(DefaultLocationButton);

  Page.Buttons[0].Top :=
    Page.Buttons[0].Top +
    ((CustomLocationButton.Top + CustomLocationButton.Height + ScaleY(8)) -
      Page.Edits[0].Top);
  Page.Edits[0].Top :=
    CustomLocationButton.Top + CustomLocationButton.Height + ScaleY(8);
  Page.Edits[0].Left := Page.Edits[0].Left + ScaleX(16);
  Page.Edits[0].Width := Page.Edits[0].Width - ScaleX(16);
  Page.Edits[0].TabOrder := CustomLocationButton.TabOrder + 1;
  Page.Buttons[0].TabOrder := Page.Edits[0].TabOrder + 1;

  LocationButtonClick(nil); { Update edit for initial state of buttons }

  OldNextButtonOnClick := WizardForm.NextButton.OnClick;
  WizardForm.NextButton.OnClick := @NextButtonOnClick;
end;

enter image description here

enter image description here


关于该主题的更一般性问题:在自定义页面上放置图像/控件的Inno Setup


1
完美运行。再次感谢。 - tg24

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接