Back to Devexpress

RichEditControl.HyperlinkClick Event

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-01e7695d.md

latest5.2 KB
Original Source

RichEditControl.HyperlinkClick Event

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

Declaration

csharp
public event HyperlinkClickEventHandler HyperlinkClick
vb
Public Event HyperlinkClick As HyperlinkClickEventHandler

Event Data

The HyperlinkClick event's data class is HyperlinkClickEventArgs. The following properties provide information specific to this event:

PropertyDescription
AltIndicates whether the ALT key was pressed.
ControlIndicates whether the CTRL key was pressed.
HandledGets or sets whether the default action associated with the hyperlink click is required.
HyperlinkGets a clicked hyperlink.
ModifierKeysDetermines which modifier keys (SHIFT, CTRL, and ALT) were pressed to activate a hyperlink.
ShiftIndicates whether the SHIFT key was pressed.

Remarks

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.

csharp
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);
}
vb
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

NavigateUri

Anchor

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace