inno setup可以很方便的打包window软件来制作安装程序。我们常需要提供复选框让用户来选择安装部分功能或软件,inno setup提供了TNewCheckBox来创建复选框,但TCheckBox适用于不互斥的选项之间,遇到互斥的选项该如何处理呢?
方法一 通过TRadioButton实现多个选项单选。
方法二 通过在TCheckBox的OnClick事件中,禁用其他复选框来达到单选的目的。
inno setup代码示例如下:
procedure ClickWinpcapCheck(Sender: TObject);
begin
//当winpcap勾选时,禁用npcap复选框
if InstallWinpcapCheckBox.Checked then
begin
InstallNpcapCheckBox.Enabled := false;
end
else
begin
InstallNpcapCheckBox.Enabled := true;
end;
end;
procedure ClickNpcapCheck(Sender: TObject);
begin
if InstallNpcapCheckBox.Checked then
begin
InstallWinpcapCheckBox.Enabled := false;
end
else
begin
InstallWinpcapCheckBox.Enabled := true;
end;
end;
procedure InitializeWizard;
var
LabelFolder: TLabel;
MainPage: TWizardPage;
FolderToInstall: TNewEdit;
begin
MainPage := CreateCustomPage(wpWelcome, ExpandConstant('{cm:driverChooseTitle}'), ExpandConstant('{cm:driverChooseDescription}'));
LabelFolder := TLabel.Create(MainPage);
LabelFolder.Parent := WizardForm;
LabelFolder.Top := 84;
LabelFolder.Left := 6;
LabelFolder.Caption := 'Directory:'
FolderToInstall := TNewEdit.Create(MainPage);
FolderToInstall.Parent := MainPage.Surface;
FolderToInstall.Top := 82;
FolderToInstall.Left := 85;
FolderToInstall.Width := 380;
FolderToInstall.Text := WizardDirValue;
FolderToInstall.ReadOnly := True;
InstallWinpcapCheckBox := TNewCheckBox.Create(MainPage);
InstallWinpcapCheckBox.Parent := MainPage.Surface;
InstallWinpcapCheckBox.Top := FolderToInstall.Top + FolderToInstall.Height + 8;
InstallWinpcapCheckBox.Left := FolderToInstall.Left;
InstallWinpcapCheckBox.Width := FolderToInstall.Width;
InstallWinpcapCheckBox.Caption := 'Install winpcap';
InstallWinpcapCheckBox.OnClick := @ClickWinpcapCheck;
InstallWinpcapCheckBox.AllowGrayed := false;
InstallNpcapCheckBox := TNewCheckBox.Create(MainPage);
InstallNpcapCheckBox.Parent := MainPage.Surface;
InstallNpcapCheckBox.Top := FolderToInstall.Top + FolderToInstall.Height + 28;
InstallNpcapCheckBox.Left := FolderToInstall.Left;
InstallNpcapCheckBox.Width := FolderToInstall.Width;
InstallNpcapCheckBox.Caption := 'Install npcap';
InstallNpcapCheckBox.OnClick := @ClickNpcapCheck;
end;
运行效果如下:
当勾选Install npcap后,Install winpcap自动变灰不可勾选。
完整脚本下载:
https://download.csdn.net/download/dongsongz/18299822