【问题标题】:TInputDirWizardPage with Radio Buttons带有单选按钮的 TInputDirWizardPage
【发布时间】:2018-08-27 18:22:56
【问题描述】:

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

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

或者我需要建立一个CustomPage 并自己定义控件吗? 如果第二个问题的答案是肯定的,我如何才能使用“目录输入”(来自TInputDirWizardPage),还是我自己也需要构建它?

【问题讨论】:

    标签: radio-button inno-setup pascalscript


    【解决方案1】:

    你猜对了,你有几个选择:

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

    第二个选项可能涉及最少的定制。虽然它需要来自 Is it possible to allow a user to skip a TInputDirWizardPage in Inno Setup? 的 hack

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


    关于该主题的更一般性问题:Inno Setup Placing image/control on custom page

    【讨论】:

    • 完美运行。再次感谢您。
    猜你喜欢
    • 2021-06-19
    • 2013-09-25
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多