用单选按钮替换安装类型下拉列表 [英] Replace installation types Dropdown list by radio buttons

查看:45
本文介绍了用单选按钮替换安装类型下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在InnoSetup中添加了不同的安装类型(安装,更新,修复).一切都很好.

I recently added different installation types (Install, Update, Repair) to my InnoSetup. It all workes pretty fine.

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

我唯一不喜欢的是在安装运行时出现的下拉列表,用于选择一种安装类型.

The only thing I do not like so much is the dropdown list, that appears when installation runs, to select one of the installation types.

是否可以通过广播组替换下拉列表?

Is there a way to replace the dropdown list by a radio group?

谢谢

推荐答案

您可以使用单选按钮(因为Inno Setup中没有可用的单选组组件):

You can use radio buttons (since there's no radio group component available in 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组件列表):

And the result (includes the iscustom component list):

或者您可以使用例如复选框列表,它可以在Inno Setup中包含单选按钮:

Or you can use e.g. check list box, which is able to contain radio buttons in Inno Setup:

[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组件列表):

And the result (includes the iscustom component list):

这篇关于用单选按钮替换安装类型下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆