Back to Devexpress

TdxHyperlinkEventArgs.URI Property

vcl-cxcontrols-dot-tdxhyperlinkeventargs-671cc232.md

latest5.4 KB
Original Source

TdxHyperlinkEventArgs.URI Property

Returns the target hyperlink’s URI.

Declaration

delphi
property URI: string read;

Property Value

TypeDescription
string

The target hyperlink’s URI.

|

Remarks

Use Text and URI properties to identify a hyperlink in a formatted message.

Code Examples

Display Target URIs of Hot-Tracked Hyperlinks in Layout Items

The code example in this section demonstrates OnHyperlinkMouseEnter and OnHyperlinkMouseLeave event handlers that update the form caption as the mouse pointer moves between layout item hyperlinks.

The OnHyperlinkMouseEnter event handler displays the target URI of a hyperlink in the form caption when the mouse pointer enters the hyperlink’s area. The OnHyperlinkMouseLeave event handler changes the form caption to a predefined string when the mouse pointer leaves a hyperlink.

Tip

This scenario can be useful if you need to display hyperlink targets without hints (if the CaptionOptions.ShowHyperlinkHint property is set to bFalse, for example).

delphi
procedure TMyForm.dxLayoutControl1Item1HyperlinkMouseEnter(Sender: TObject;
  AArgs: TdxHyperlinkEventArgs); // Displays the hyperlink target in the form caption
begin
  Caption := 'Navigate to ' + AArgs.URI;
end;

procedure TMyForm.dxLayoutControl1Item1HyperlinkMouseLeave(Sender: TObject;
  AArgs: TdxHyperlinkEventArgs); // Displays the predefined string instead of a hyperlink target
begin
  Caption := 'Hyperlink Navigation in Layout Item Captions';
end;
cpp
void __fastcall TMyForm::dxLayoutControl1Item1HyperlinkMouseEnter(TObject *Sender,
  TdxHyperlinkEventArgs *AArgs) // Displays the hyperlink target in the form caption
{
  Caption = "Navigate to " + AArgs->URI;
}

void __fastcall TMyForm::dxLayoutControl1Item1HyperlinkMouseLeave(TObject *Sender,
  TdxHyperlinkEventArgs *AArgs) // Displays the predefined string instead of a hyperlink target
{
  Caption = "Hyperlink Navigation in Layout Item Captions";
}

Prevent Accidental Hyperlink Activation in Formatted Labels

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.

delphi
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;
cpp
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

TdxHyperlinkEventArgs.HyperlinkIndex Property

TdxHyperlinkEventArgs.Item Property

TdxHyperlinkEventArgs Class

TdxHyperlinkEventArgs Members

cxControls Unit