如何添加可点击的链接到自定义的Inno Setup WelcomeLabel? [英] How to add clickable links to custom Inno Setup WelcomeLabel?

查看:112
本文介绍了如何添加可点击的链接到自定义的Inno Setup WelcomeLabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义WelcomeLabel2消息的Inno Setup程序.

I have an Inno Setup program with a custom WelcomeLabel2 message.

[Messages]
WelcomeLabel2=Lorem ipsum dolor sit amet CLICK_HERE consectetur adipiscing elit.

我正在尝试将CLICK_HERE设置为网站的可点击链接.

I am trying to make the CLICK_HERE a clickable link to a website.

我想知道的另一件事是如何使此CLICK_HERE文本粗体.

Another thing I am wondering is how to make this CLICK_HERE text bold.

我该如何实现?

推荐答案

这并不容易.

要创建可整体单击的标签,您可以使用以下代码:

To create a label that is clickable whole, you can use a code like:

procedure OpenBrowser(Url: string);
var
  ErrorCode: Integer;
begin
  ShellExec('open', Url, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;

procedure LinkClick(Sender: TObject);
begin
  OpenBrowser('https://www.example.com/');
end;

procedure InitializeWizard;
var
  Link: TLabel;
begin
  Link := TLabel.Create(WizardForm);
  Link.Left := ???;
  Link.Top := ???;
  Link.Parent := WizardForm.WelcomePage;
  Link.Caption := 'CLICK_HERE';
  Link.OnClick := @LinkClick;
  Link.ParentFont := True;
  Link.Font.Style := Link.Font.Style + [fsUnderline, fsBold];
  Link.Font.Color := clBlue;
  Link.Cursor := crHand;
end;

另请参见在安装时在Inno Setup中显示许可协议链接.

尽管创建仅文本部分可点击的标签是一种更困难的方法.如果文本适合一行,则可以通过将三个标签彼此相邻堆叠来实现(首先是前导静态文本,然后是链接,然后是尾随静态文本).但是,如果文本不能排成一行,则这是不可能的,因为标签会相互重叠.

Though to create a label that have just parts of its text clickable is a way more difficult. If the text fits on one line, it's doable by stacking three labels next to each other (first the leading static text, then link, followed by the trailing static text). But if the text does not fit on one line, it's not doable, as the labels would overlap each other.

或者,您可以使用链接创建一个RTF文档,并使用只读的TRichEditViewer呈现该文档:

Alternatively, you can create an RTF document with the link and present it using a read-only TRichEditViewer:

procedure InitializeWizard;
var
  RichViewer: TRichEditViewer;
begin
  RichViewer := TRichEditViewer.Create(WizardForm);
  RichViewer.Left := WizardForm.WelcomeLabel2.Left;
  RichViewer.Top := WizardForm.WelcomeLabel2.Top;
  RichViewer.Width := WizardForm.WelcomeLabel2.Width;
  RichViewer.Height := WizardForm.WelcomeLabel2.Height;
  RichViewer.Parent := WizardForm.WelcomeLabel2.Parent;
  RichViewer.BorderStyle := bsNone;
  RichViewer.TabStop := False;
  RichViewer.ReadOnly := True;
  WizardForm.WelcomeLabel2.Visible := False;

  RichViewer.RTFText :=
    '{\rtf1 Lorem ipsum dolor sit amet ' +
    '{\b {\field{\*\fldinst{HYPERLINK "https://www.example.com/" }}' + 
    '{\fldrslt{CLICK_HERE}}}} ' +
    'consectetur adipiscing elit.}';
end;

为此,您需要Unicode版本(Inno Setup 6唯一的版本),请参见如何在使用RichEditViewer进行Inno设置吗?

You need Unicode version (the only version as of Inno Setup 6) for this, see How to add clickable links to custom page in Inno Setup using RichEditViewer?

要更改链接颜色,请参见 Inno设置-如何更改RTF文本中超链接的颜色?

To change the link color, see Inno Setup - How to change the color of the hyperlink in RTF text?

这篇关于如何添加可点击的链接到自定义的Inno Setup WelcomeLabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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