Back to Devexpress

HyperLinkEdit.OpenLink Event

windowsforms-devexpress-dot-xtraeditors-dot-hyperlinkedit-412b2ef6.md

latest4.1 KB
Original Source

HyperLinkEdit.OpenLink Event

Occurs before hyperlink execution.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event OpenLinkEventHandler OpenLink
vb
<DXCategory("Events")>
Public Event OpenLink As OpenLinkEventHandler

Event Data

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

PropertyDescription
EditValueGets or sets the object representing the command to execute.
HandledGets or sets whether default execution of the hyperlink command is required.

Remarks

The OpenLink event is fired before hyperlink execution. The event lets you modify the command to execute, perform actions and to cancel default processing.

The editor’s OpenLink event is equivalent to the RepositoryItemHyperLinkEdit.OpenLink event available via the HyperLinkEdit.Properties object, i.e. adding/removing an event handler for the current event actually affects the RepositoryItemHyperLinkEdit.OpenLink event.

Refer to the RepositoryItemHyperLinkEdit.OpenLink topic for more information.

Example

Suppose that a hyperlink editor is used to display e-mails. When you activate the hyperlink, the default mail client should be opened for the specified address. The problem is that a hyperlink editor will run the mail client only if the command contains a “mailto:” prefix. So a command such as “[email protected]” is not recognized by the editor by default.

Assuming that the hyperlink editor represents e-mails, we handle the HyperLinkEdit.OpenLink event and check whether the command contains the “mailto:” prefix. If not, we add it to the command. After the event handler is processed, the command will be executed by the editor (the OpenLinkEventArgs.Handled property of the event parameter is false by default) and this will open the mail client.

csharp
using DevExpress.XtraEditors.Controls;

this.hyperLinkEdit2.EditValue = "[email protected]";
//...
private void hyperLinkEdit2_OpenLink(object sender, OpenLinkEventArgs e) {
    const string mailPrefix = "mailto:";
    if(!e.EditValue.ToString().ToLower().StartsWith(mailPrefix)) {
        e.EditValue = mailPrefix + e.EditValue.ToString();
    }
}
vb
Me.HyperLinkEdit2.EditValue = "[email protected]"
'...
Private Sub HyperLinkEdit2_OpenLink(ByVal sender As System.Object, _
  ByVal e As DevExpress.XtraEditors.Controls.OpenLinkEventArgs) _
  Handles HyperLinkEdit2.OpenLink
    Const mailPrefix As String = "mailto:"
    If Not e.EditValue.ToString().ToLower().StartsWith(mailPrefix) Then
        e.EditValue = mailPrefix + e.EditValue.ToString()
    End If
End Sub

See Also

OpenLink

HyperLinkEdit Class

HyperLinkEdit Members

DevExpress.XtraEditors Namespace