用单独的页面上的单选按钮替换Inno Setup安装类型组合框(像Install Shield一样)

时间:2018-05-21 09:49:19

标签: inno-setup

我正在为我的应用程序使用Inno Setup生成安装程序。

要使用户能够选择完整或紧凑的安装,我使用以下代码,

[Types]
Name: "full"; Description: "Full Installation"
Name: "compact"; Description: "Lite Installation"
Name: "custom"; Description: "Custom Installation"; Flags: iscustom

[Components]
Name: "One"; Description: "First"; Types: full compact custom; Flags: fixed
Name: "Two"; Description: "second"; Types: full
Name: "Three"; Description: "Third"; Types: full
Name: "Four"; Description: "Fourth"; Types: full
Name: "Five"; Description: "Fifth"; Types: full

我得到以下用户界面:

enter image description here

有没有可能改变这种方式(通过组合框)选择“类型”?

我想要“类型”选择,就像下面的例子一样。如果用户选择自定义,他应该能够选择要安装的“组件”。

enter image description here

1 个答案:

答案 0 :(得分:3)

一种方法是使用"类型"来实现自定义页面。菜单,隐藏标准"类型"组合框,并根据用户在自定义菜单中选择的类型更新其选择。

[Types]
Name: "typical"; Description: "Typical installation"
Name: "complete"; Description: "Complete installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "main"; Description: "Main Files"; Types: complete typical custom; Flags: fixed
Name: "help"; Description: "Help Files"; Types: complete
Name: "help\english"; Description: "English"; Types: complete
Name: "help\dutch"; Description: "Dutch"; Types: complete

[Code]

var
  TypesPage: TWizardPage;
  TypicalButton: TNewRadioButton;
  CompleteButton: TNewRadioButton;
  CustomButton: TNewRadioButton;

procedure InitializeWizard();
begin
  { Create custom "types" page }
  TypesPage :=
    CreateCustomPage(
      wpSelectDir, 'Setup Type', 'Choose the setup type that best suits your needs.');

  TypicalButton := TNewRadioButton.Create(TypesPage);
  TypicalButton.Parent := TypesPage.Surface;
  TypicalButton.Caption := 'Typical';
  TypicalButton.Height := ScaleY(TypicalButton.Height);
  TypicalButton.Checked := True; { default, unless other type is selected below }

  CompleteButton := TNewRadioButton.Create(TypesPage);
  CompleteButton.Parent := TypesPage.Surface;
  CompleteButton.Caption := 'Complete';
  CompleteButton.Height := ScaleY(CompleteButton.Height);
  CompleteButton.Top := TypicalButton.Top + TypicalButton.Height + ScaleY(16);
  CompleteButton.Checked := (WizardForm.TypesCombo.ItemIndex = 1);

  CustomButton := TNewRadioButton.Create(TypesPage);
  CustomButton.Parent := TypesPage.Surface;
  CustomButton.Caption := 'Custom';
  CustomButton.Height := ScaleY(CustomButton.Height);
  CustomButton.Top := CompleteButton.Top + CompleteButton.Height + ScaleY(16);
  CompleteButton.Checked := (WizardForm.TypesCombo.ItemIndex = 2);

  { Hide "types" combo }
  WizardForm.TypesCombo.Visible := False;
  WizardForm.IncTopDecHeight(WizardForm.ComponentsList,
    -(WizardForm.ComponentsList.Top - WizardForm.TypesCombo.Top));
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  { When leaving "types" page, update hidden "types" combo box }
  { according to user selection... }
  if CurPageID = TypesPage.ID then
  begin
    if CompleteButton.Checked then WizardForm.TypesCombo.ItemIndex := 1
      else 
    if CustomButton.Checked then WizardForm.TypesCombo.ItemIndex := 2
      else WizardForm.TypesCombo.ItemIndex := 0;
    { .. and have Inno Setup update components selection accordingly }
    WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo);
  end;
  Result := True;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  { Skip "components" page, unless "custom" type was selected }
  Result := (PageID = wpSelectComponents) and (not CustomButton.Checked);
end;

enter image description here

enter image description here

要添加其他图像和标签,请参阅:
Inno Setup Placing image/control on custom page

对于替代实现,它显示"选择组件"上的单选按钮。页面,见:
Replace installation types Dropdown list by radio buttons