Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Customize HyperLinkEdit's Command via Event

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 “noreply@devexpress.com” 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.

using DevExpress.XtraEditors.Controls;

this.hyperLinkEdit2.EditValue = "noreply@devexpress.com";
//...
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();
    }
}