带有单选按钮的 TInputDirWizardPage [英] TInputDirWizardPage with Radio Buttons

查看:26
本文介绍了带有单选按钮的 TInputDirWizardPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need a setup page with two radio buttons. Clicking the second button should enable an input to define a path (Like it's done in TInputDirWizardPage).

Is it possible to customize TInputDirWizardPage for my needs?

Or do I need to build a CustomPage and define the controls by myself? If the second question will be answered with yes, how am I able to use the "directory input" (from the TInputDirWizardPage), or is it also neccessary to build this on my own?

解决方案

As you correctly guessed you have several options:

  1. Start with TWizardPage and build everything from scratch
  2. Start with TInputDirWizardPage and add the radio buttons
  3. Start with TInputOptionWizardPage and add the edit box

The second option probably involves least customization. Though it needs a hack from Is it possible to allow a user to skip a TInputDirWizardPage in Inno Setup?

{ WORKAROUND }
{ Checkboxes and Radio buttons created on runtime do }
{ not scale their height automatically. }
{ See https://stackoverflow.com/q/30469660/850848 }
procedure ScaleFixedHeightControl(Control: TButtonControl);
begin
  Control.Height := ScaleY(Control.Height);
end;

var
  Page: TInputDirWizardPage;
  DefaultLocationButton: TRadioButton;
  CustomLocationButton: TRadioButton;
  OldNextButtonOnClick: TNotifyEvent;

procedure LocationButtonClick(Sender: TObject);
begin
  Page.Edits[0].Enabled := CustomLocationButton.Checked;
  Page.Buttons[0].Enabled := CustomLocationButton.Checked;
end;

procedure NextButtonOnClick(Sender: TObject);
var
  PrevDir: string;
begin
  { Do not validate, when "default location" is selected }
  if (WizardForm.CurPageID = Page.ID) and DefaultLocationButton.Checked then
  begin
    PrevDir := Page.Values[0];
    Page.Values[0] := GetWinDir; { Force value to pass validation }
    OldNextButtonOnClick(Sender);
    Page.Values[0] := PrevDir;
  end
    else
  begin
    OldNextButtonOnClick(Sender);
  end;
end;

procedure InitializeWizard();
begin
  Page := CreateInputDirPage(
    wpWelcome,
    'Select Personal Data Location', 'Where should personal data files be stored?',
    '', False, 'New Folder');
  Page.Add('');

  DefaultLocationButton := TRadioButton.Create(WizardForm);
  DefaultLocationButton.Parent := Page.Surface;
  DefaultLocationButton.Top := Page.Edits[0].Top;
  DefaultLocationButton.Caption := 'Use default location';
  DefaultLocationButton.Checked := True;
  DefaultLocationButton.OnClick := @LocationButtonClick;
  ScaleFixedHeightControl(DefaultLocationButton);
  
  CustomLocationButton := TRadioButton.Create(WizardForm);
  CustomLocationButton.Parent := Page.Surface;
  CustomLocationButton.Top :=
    DefaultLocationButton.Top + DefaultLocationButton.Height + ScaleY(8);
  CustomLocationButton.Caption := 'Use custom location';
  CustomLocationButton.OnClick := @LocationButtonClick;
  ScaleFixedHeightControl(DefaultLocationButton);

  Page.Buttons[0].Top :=
    Page.Buttons[0].Top +
    ((CustomLocationButton.Top + CustomLocationButton.Height + ScaleY(8)) -
      Page.Edits[0].Top);
  Page.Edits[0].Top :=
    CustomLocationButton.Top + CustomLocationButton.Height + ScaleY(8);
  Page.Edits[0].Left := Page.Edits[0].Left + ScaleX(16);
  Page.Edits[0].Width := Page.Edits[0].Width - ScaleX(16);
  Page.Edits[0].TabOrder := CustomLocationButton.TabOrder + 1;
  Page.Buttons[0].TabOrder := Page.Edits[0].TabOrder + 1;

  LocationButtonClick(nil); { Update edit for initial state of buttons }

  OldNextButtonOnClick := WizardForm.NextButton.OnClick;
  WizardForm.NextButton.OnClick := @NextButtonOnClick;
end;


More general question on the topic: Inno Setup Placing image/control on custom page.

这篇关于带有单选按钮的 TInputDirWizardPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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