2013-02-28 51 views
3

我最近为我的InnoSetup添加了不同的安装类型(安装,更新,修复)。这一切工作都很好。替换安装类型通过单选按钮下拉列表

[Types] 
Name: Install; Description: "Install OLP"; 
Name: Update; Description: "Update an existing version of OLP"; 
Name: Repair; Description: "Repair OLP"; 

我唯一不喜欢那么多的下拉列表中,当安装运行,选择安装类型之一出现。

有没有办法用无线电组代替下拉列表?

感谢

回答

13

您可以使用单选按钮(因为有在Inno Setup的可用的无线电组件组):

[Code] 
procedure OnTypeChange(Sender: TObject); 
begin 
    // set the item index in hidden TypesCombo 
    WizardForm.TypesCombo.ItemIndex := TNewRadioButton(Sender).Tag; 
    // notify TypesCombo about the selection change 
    WizardForm.TypesCombo.OnChange(nil); 
end; 

procedure InitializeWizard; 
var 
    I: Integer; 
    RadioButton: TNewRadioButton; 
begin 
    for I := 0 to WizardForm.TypesCombo.Items.Count - 1 do 
    begin 
    // create radio button and set the basic properties 
    RadioButton := TNewRadioButton.Create(WizardForm); 
    RadioButton.Parent := WizardForm.SelectComponentsPage; 
    RadioButton.Left := WizardForm.TypesCombo.Left; 
    RadioButton.Top := WizardForm.TypesCombo.Top + I * RadioButton.Height; 
    RadioButton.Width := WizardForm.TypesCombo.Width; 
    // check just the first item 
    RadioButton.Checked := I = 0; 
    RadioButton.Caption := WizardForm.TypesCombo.Items[I]; 
    // the Tag property substitutes the index property 
    RadioButton.Tag := I; 
    RadioButton.TabOrder := I;  
    RadioButton.OnClick := @OnTypeChange; 
    end; 
    // hide the TypesCombo combo box 
    WizardForm.TypesCombo.Visible := False; 

    // if you're not using the "iscustom" flag in any type entry, you can remove 
    // the following lines, because they resize and reposition the check list box 
    // for component selection, which is hidden, if you don't use "iscustom" flag 
    I := WizardForm.ComponentsList.Top - 
    (RadioButton.Top + RadioButton.Height + 8); 
    WizardForm.ComponentsList.Top := RadioButton.Top + RadioButton.Height + 8; 
    WizardForm.ComponentsList.Height := WizardForm.ComponentsList.Height + I; 
end; 

而结果(包括iscustom组件列表):

enter image description here

或者您可以使用eg检查列表框,其能够包含在创新安装单选按钮:

[Code] 
procedure OnTypeChange(Sender: TObject); 
begin 
    // set the item index in hidden TypesCombo 
    WizardForm.TypesCombo.ItemIndex := TNewCheckListBox(Sender).ItemIndex; 
    // notify TypesCombo about the selection change 
    WizardForm.TypesCombo.OnChange(nil); 
end; 

procedure InitializeWizard; 
var 
    I: Integer; 
    CheckListBox: TNewCheckListBox; 
begin 
    // create the TNewCheckListBox object and set the basic properties 
    CheckListBox := TNewCheckListBox.Create(WizardForm); 
    CheckListBox.Parent := WizardForm.SelectComponentsPage; 
    CheckListBox.Left := WizardForm.TypesCombo.Left; 
    CheckListBox.Top := WizardForm.TypesCombo.Top; 
    CheckListBox.Width := WizardForm.TypesCombo.Width; 
    CheckListBox.Height := CheckListBox.MinItemHeight * 
    WizardForm.TypesCombo.Items.Count + 4; 
    CheckListBox.TabOrder := 0; 
    // assign the selection change event 
    CheckListBox.OnClickCheck := @OnTypeChange; 
    // add radio buttons from all TypesCombo items, select the first item 
    for I := 0 to WizardForm.TypesCombo.Items.Count - 1 do 
    CheckListBox.AddRadioButton(WizardForm.TypesCombo.Items[I], 
     '', 0, I = 0, True, nil); 
    // hide the TypesCombo combo box 
    WizardForm.TypesCombo.Visible := False; 

    // if you're not using the "iscustom" flag in any type entry, you can remove 
    // the following lines, because they resize and reposition the check list box 
    // for component selection, which is hidden, if you don't use "iscustom" flag 
    I := WizardForm.ComponentsList.Top - 
    (CheckListBox.Top + CheckListBox.Height + 8); 
    WizardForm.ComponentsList.Top := CheckListBox.Top + 
    CheckListBox.Height + 8; 
    WizardForm.ComponentsList.Height := WizardForm.ComponentsList.Height + I; 
end; 

而结果(包括iscustom部件列表):

enter image description here

+0

嗨TLama,非常感谢你的解决方案。它工作完美。 – 2013-03-01 07:17:10

+0

不客气! – TLama 2013-03-01 13:22:53

+0

您应该按照[按字体大小缩放单选按钮列表](http://stackoverflow.com/q/30469660/850848) – 2015-05-27 09:02:31

0

这方面的一个整洁的解决办法是在组件选择页面之前使用CreateInputOptionPage创建一个带单选按钮的单独页面。 (CodeDlg.iss脚本中有这样的例子。)

甚至更​​整洁的选项根本不要问,因为它完全没有必要。你可以自动检测已经安装的版本 - 如果没有安装它,它是一个安装,如果它已经安装但是较旧,它是一个升级版,如果它已经安装并且版本相同,那么它是一个修复版,最后如果它安装了但是更新那么这是降级 - 您可能想要禁止(更安全)或允许但显示警告(如果人们可能想要降级,则更方便)。

+0

我完全同意你的提示。我将在未来尝试改进设置,但目前,TLama的上述方法对我来说更简单:-) – 2013-03-01 07:20:17