2013-02-28 50 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