windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-01e7695d.md
Occurs when an end-user clicks the hyperlink to activate it.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.XtraRichEdit.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public event HyperlinkClickEventHandler HyperlinkClick
Public Event HyperlinkClick As HyperlinkClickEventHandler
The HyperlinkClick event's data class is HyperlinkClickEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Alt | Indicates whether the ALT key was pressed. |
| Control | Indicates whether the CTRL key was pressed. |
| Handled | Gets or sets whether the default action associated with the hyperlink click is required. |
| Hyperlink | Gets a clicked hyperlink. |
| ModifierKeys | Determines which modifier keys (SHIFT, CTRL, and ALT) were pressed to activate a hyperlink. |
| Shift | Indicates whether the SHIFT key was pressed. |
Handle this event to perform a custom action that depends on hyperlink properties. By default, activating a hyperlink results in navigating to the location specified by the Hyperlink.NavigateUri or the Hyperlink.Anchor property values.
In the code sample below, this event handler is used to invoke a form with the data list. The end-user can select the item from the pop-up list and it automatically replaces the hyperlink content. Refer to the How to: Handle the HyperlinkClick Event to Invoke the Custom Form for a complete example.
public Hyperlink activeLink;
void OnHyperlinkClick(object sender, HyperlinkClickEventArgs e)
{
activeLink = e.Hyperlink;
SelectProductForm form = new SelectProductForm(products);
// Set the Commit event handler:
form.Commit += OnProductFormCommit;
// Set the Range property to the hyperlink range:
form.Range = activeLink.Range;
// Set the Location property to specify the location where the form is going to be invoked:
form.Location = GetFormLocation();
form.Show();
e.Handled = true;
}
// This method places the form to the right of the cursor position:
Point GetFormLocation()
{
DocumentPosition position = this.richEditControl1.Document.CaretPosition;
Rectangle rect = this.richEditControl1.GetBoundsFromPosition(position);
Point location = new Point(rect.Right, rect.Bottom);
Point localPoint = Units.DocumentsToPixels(location, this.richEditControl1.DpiX, this.richEditControl1.DpiY);
return this.richEditControl1.PointToScreen(localPoint);
}
Public activeLink As Hyperlink
Private Sub OnHyperlinkClick(ByVal sender As Object, ByVal e As HyperlinkClickEventArgs)
activeLink = e.Hyperlink
Dim form As New SelectProductForm(products)
' Set the Commit event handler:
AddHandler form.Commit, AddressOf OnProductFormCommit
' Set the Range property to the hyperlink range:
form.Range = activeLink.Range
' Specify the Location property to specify the location where the form is going to be invoked:
form.Location = GetFormLocation()
form.Show()
e.Handled = True
End Sub
' This method places the form to the right of the cursor position:
Private Function GetFormLocation() As Point
Dim position As DocumentPosition = Me.richEditControl1.Document.CaretPosition
Dim rect As Rectangle = Me.richEditControl1.GetBoundsFromPosition(position)
Dim location As New Point(rect.Right, rect.Bottom)
Dim localPoint As Point = Units.DocumentsToPixels(location, Me.richEditControl1.DpiX, Me.richEditControl1.DpiY)
Return Me.richEditControl1.PointToScreen(localPoint)
End Function
See Also