vcl-dxformattedlabel-dot-tdxcustomformattedlabelproperties.md
Allows you to respond to a click on a hyperlink or prevent hyperlink activation.
property OnHyperlinkClick: TdxHyperlinkClickEvent read; write;
A click on a hyperlink defined as a part of a formatted label caption invokes the default application associated with the hyperlink’s URI scheme (a browser for HTTP and HTTPS, a mail client for MAILTO, etc.)
You can handle the OnHyperlinkClick event to execute custom code in response to a click on a hyperlink in the formatted label’s caption or prevent hyperlink activation depending on certain conditions in your application.
The OnHyperlinkClick event occurs every time a user clicks a hyperlink in the formatted label.
The following parameters are accessible within an OnHyperlinkClick event handler:
SenderProvides access to the formatted label that raised the hyperlink click event.AArgs
Provides access to information related to the hyperlink click event that occurred and allows you to prevent hyperlink activation. You can use AArgs.Button and AArgs.Shift properties to identify the clicked mouse button and the state of modifier keys at the moment of event occurrence.
Refer to the TdxHyperlinkClickEventArgs procedural type description for detailed information on all options accessible within an OnHyperlinkClick event handler.
Refer to the TdxHyperlinkClickEvent procedural type description for details.
The code example in this section demonstrates handlers of OnHyperlinkClick and OnShowHyperlinkHint events. The OnHyperlinkClick event handler requires a user to hold down the Ctrl key to activate a hyperlink. The OnShowHyperlinkHint event handler changes all hyperlink hints to prompt a user to hold the Ctrl key for hyperlink activation.
procedure TMyForm.dxFormattedLabel1PropertiesHyperlinkClick(Sender: TObject;
AArgs: TdxHyperlinkClickEventArgs); // Requires the Ctrl key for hyperlink activation
begin
if AArgs.Shift <> [ssCtrl] then // If the Ctrl key is not held down
AArgs.Handled := True; // Prevents hyperlink activation
end;
procedure TMyForm.dxFormattedLabel1PropertiesShowHyperlinkHint(Sender: TObject;
AArgs: TdxShowHyperlinkHintEventArgs); // Changes all hyperlink hints
var
AHintPrefix, AHintURI: string;
begin
AHintPrefix := 'Ctrl-click to navigate to ';
AHintURI := AArgs.URI.Remove(0, 8); // Removes the URI scheme from the hyperlink hint
AArgs.Hint := AHintPrefix + AHintURI; // Redefines the hyperlink hint
end;
void __fastcall TMyForm::dxFormattedLabel1PropertiesHyperlinkClick(TObject *Sender,
TdxHyperlinkClickEventArgs *AArgs) // Requires the Ctrl key for hyperlink activation
{
if(AArgs->Shift != (TShiftState() << [ssCtrl])) // If the Ctrl key is not held down
AArgs->Handled = true; // Prevents hyperlink activation
}
void __fastcall TMyForm::dxFormattedLabel1PropertiesShowHyperlinkHint(TObject *Sender,
TdxShowHyperlinkHintEventArgs *AArgs) // Changes all hyperlink hints
{
UnicodeString AHintPrefix, AHintURI;
AHintPrefix = "Ctrl-click to navigate to ";
AHintURI = AArgs->URI.Remove(0, 8); // Removes the URI scheme from the hyperlink hint
AArgs->Hint = AHintPrefix + AHintURI; // Redefines the hyperlink hint
}
See Also
TdxCustomFormattedLabelProperties.OnHyperlinkMouseEnter Event
TdxCustomFormattedLabelProperties.OnHyperlinkMouseLeave Event
TdxCustomFormattedLabelProperties.OnShowHyperlinkHint Event
BBCode-Inspired Text Formatting Markup
TdxCustomFormattedLabelProperties Class