在Inno Setup中,是否可以创建一个在单选按钮内有输入文件小工具的页面?

时间:2014-08-25 13:01:05

标签: inno-setup

在Inno Setup中,您可以拥有一个TInputFileWizardPage,其中包含一个不错的文件选择小工具。但是你可以在通用的TWizardPage上放置相同的小工具吗?具体来说,我希望有单选按钮,以便在激活一个特定选项时使用文件小工具。

1 个答案:

答案 0 :(得分:2)

比构建自己的输入文件页面更容易修改创建的TInputFileWizardPage页面。以下示例添加了两个单选按钮并移动输入文件项组件。默认情况下,禁用输入文件组件,并选择第一个单选按钮。如果用户选择第二个单选按钮,则启用输入文件组件:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
var
  InputPage: TInputFileWizardPage;
  RadioButtons: array[0..1] of TNewRadioButton;

procedure ShiftFilePageItem(Page: TInputFileWizardPage; Index: Integer;
  Offset: Integer);
begin
  Page.Edits[Index].Top := Page.Edits[Index].Top + Offset;
  Page.Buttons[Index].Top := Page.Buttons[Index].Top + Offset;
  Page.PromptLabels[Index].Top := Page.PromptLabels[Index].Top + Offset;
end;

procedure SetFilePageItemEnabled(Page: TInputFileWizardPage; Index: Integer;
  Enabled: Boolean);
begin
  Page.Edits[Index].Enabled := Enabled;
  Page.Buttons[Index].Enabled := Enabled;
  Page.PromptLabels[Index].Enabled := Enabled;
end;

procedure RadioButtonClick(Sender: TObject);
begin
  SetFilePageItemEnabled(InputPage, 0, Sender = RadioButtons[1]);
end;

procedure InitializeWizard;
begin
  InputPage := CreateInputFilePage(wpWelcome, 'Caption', 'Description',
    'SubCaption');
  InputPage.Add('Prompt', 'All files|*.*', '*.*');

  RadioButtons[0] := TNewRadioButton.Create(InputPage);
  RadioButtons[0].Parent := InputPage.Surface;
  RadioButtons[0].Left := 0;
  RadioButtons[0].Top := 0;
  RadioButtons[0].Width := InputPage.SurfaceWidth;
  RadioButtons[0].Checked := True;
  RadioButtons[0].Caption := 'Option with no file selection';
  RadioButtons[0].OnClick := @RadioButtonClick;

  RadioButtons[1] := TNewRadioButton.Create(InputPage);
  RadioButtons[1].Parent := InputPage.Surface;
  RadioButtons[1].Left := RadioButtons[0].Left;
  RadioButtons[1].Top := RadioButtons[0].Top + RadioButtons[0].Height + 2;
  RadioButtons[1].Width := InputPage.SurfaceWidth;
  RadioButtons[1].Checked := False;
  RadioButtons[1].Caption := 'Option with file selection';
  RadioButtons[1].OnClick := @RadioButtonClick;

  ShiftFilePageItem(InputPage, 0, RadioButtons[1].Top);
  SetFilePageItemEnabled(InputPage, 0, False);
end;

这是默认情况下页面的样子:

enter image description here