I have an Inno Setup program with a custom WelcomeLabel2
message.
[Messages]
WelcomeLabel2=Lorem ipsum dolor sit amet CLICK_HERE consectetur adipiscing elit.
I am trying to make the CLICK_HERE
a clickable link to a website.
Another thing I am wondering is how to make this CLICK_HERE
text bold.
How can I achieve this?
It's not easy.
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;
See also Show License Agreement link in Inno Setup while installation.
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.
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;
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?
To change the link color, see Inno Setup - How to change the color of the hyperlink in RTF text?
As @Bill_Stewart commented, you should avoid starting the browser with elevated privileges. For a solution, see How to open a web site after uninstallation in non-elevated mode?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With