带有单选按钮的TInputDirWizardPage

时间:2018-03-19 08:43:36

标签: radio-button inno-setup

我需要一个带有两个单选按钮的设置页面。单击第二个按钮应该启用输入来定义路径(就像它在TInputDirWizardPage中完成的那样)。

是否可以根据我的需要自定义TInputDirWizardPage

或者我是否需要构建CustomPage并自行定义控件? 如果第二个问题将回答是,我怎么能使用"目录输入" (来自TInputDirWizardPage),还是有必要自己构建它?

1 个答案:

答案 0 :(得分:2)

正如您所猜测的,您有几种选择:

  1. TWizardPage开始,从头开始构建所有内容
  2. TInputDirWizardPage开始,然后添加单选按钮
  3. TInputOptionWizardPage开始,添加编辑框
  4. 第二个选项可能涉及最少的自定义。虽然它需要来自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