You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在InnoSetup密码界面添加跳转至密码页面的链接

在InnoSetup密码页添加密码获取跳转控件

以下是基于你现有脚本,添加文本链接或按钮的实现方案,两种方式任选其一即可:

方案一:添加可点击的文本链接

直接在显示密码复选框下方添加文本链接,点击后打开密码获取网页:

var
  ShowPasswordCheck: TNewCheckBox;
  PasswordLink: TNewStaticText; // 新增文本链接控件

procedure ShowPasswordCheckClick(Sender: TObject);
begin
  WizardForm.PasswordEdit.Password := not ShowPasswordCheck.Checked;
end;

// 文本链接点击事件:打开指定网页
procedure PasswordLinkClick(Sender: TObject);
begin
  // 替换为你的密码获取网页地址
  ShellExecute(0, 'open', 'https://你的密码获取网页地址', '', '', SW_SHOWNORMAL);
end;

<event('InitializeWizard')>
procedure InitializeWizardRevealPassword();
begin
  // 原有显示密码复选框代码
  ShowPasswordCheck := TNewCheckBox.Create(WizardForm);
  ShowPasswordCheck.Parent := WizardForm.PasswordEdit.Parent; 
  ShowPasswordCheck.Caption := '&Show password';
  ShowPasswordCheck.Top :=
    WizardForm.PasswordEdit.Top + WizardForm.PasswordEdit.Height + ScaleY(8);
  ShowPasswordCheck.Height := ScaleY(ShowPasswordCheck.Height);
  ShowPasswordCheck.Checked := not WizardForm.PasswordEdit.Password;
  ShowPasswordCheck.OnClick := @ShowPasswordCheckClick;

  // 新增文本链接控件
  PasswordLink := TNewStaticText.Create(WizardForm);
  PasswordLink.Parent := WizardForm.PasswordEdit.Parent;
  PasswordLink.Caption := '<a href="">获取安装密码</a>'; // 显示的链接文本
  PasswordLink.Font.Color := clBlue; // 设置蓝色模拟链接样式
  PasswordLink.Font.Style := [fsUnderline];
  PasswordLink.Cursor := crHandPoint; // 鼠标悬停显示手型
  // 设置位置:在显示密码复选框下方8像素处
  PasswordLink.Top := ShowPasswordCheck.Top + ShowPasswordCheck.Height + ScaleY(8);
  PasswordLink.Height := ScaleY(PasswordLink.Height);
  PasswordLink.OnClick := @PasswordLinkClick;
end;

方案二:添加按钮控件

如果偏好按钮样式,可替换文本链接为按钮:

var
  ShowPasswordCheck: TNewCheckBox;
  GetPasswordBtn: TButton; // 新增按钮控件

procedure ShowPasswordCheckClick(Sender: TObject);
begin
  WizardForm.PasswordEdit.Password := not ShowPasswordCheck.Checked;
end;

// 按钮点击事件:打开指定网页
procedure GetPasswordBtnClick(Sender: TObject);
begin
  // 替换为你的密码获取网页地址
  ShellExecute(0, 'open', 'https://你的密码获取网页地址', '', '', SW_SHOWNORMAL);
end;

<event('InitializeWizard')>
procedure InitializeWizardRevealPassword();
begin
  // 原有显示密码复选框代码
  ShowPasswordCheck := TNewCheckBox.Create(WizardForm);
  ShowPasswordCheck.Parent := WizardForm.PasswordEdit.Parent; 
  ShowPasswordCheck.Caption := '&Show password';
  ShowPasswordCheck.Top :=
    WizardForm.PasswordEdit.Top + WizardForm.PasswordEdit.Height + ScaleY(8);
  ShowPasswordCheck.Height := ScaleY(ShowPasswordCheck.Height);
  ShowPasswordCheck.Checked := not WizardForm.PasswordEdit.Password;
  ShowPasswordCheck.OnClick := @ShowPasswordCheckClick;

  // 新增按钮控件
  GetPasswordBtn := TButton.Create(WizardForm);
  GetPasswordBtn.Parent := WizardForm.PasswordEdit.Parent;
  GetPasswordBtn.Caption := '获取安装密码';
  // 设置位置:在显示密码复选框下方8像素处,可按需调整Left值
  GetPasswordBtn.Top := ShowPasswordCheck.Top + ShowPasswordCheck.Height + ScaleY(8);
  GetPasswordBtn.Left := WizardForm.PasswordEdit.Left;
  GetPasswordBtn.Width := ScaleX(120);
  GetPasswordBtn.Height := ScaleY(24);
  GetPasswordBtn.OnClick := @GetPasswordBtnClick;
end;

注意事项

  • 请将代码中的https://你的密码获取网页地址替换为实际的密码获取页面URL;
  • 可根据界面布局需求,调整控件的Top、Left、Width等属性值,适配你的安装向导样式;
  • 若脚本报错,可在开头添加#include <ShellAPI>引入相关单元。

内容的提问来源于stack exchange,提问作者Vampire

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 04:50:25