How to: Implement Hyperlink Functionality by Handling OpenLink Event

  • 2 minutes to read

The following example shows how to implement hyperlink functionality by handling the HyperLinkEdit.OpenLink event. The hyperlink command is not required by this example.

Instead we handle the HyperLinkEdit.OpenLink event, which occurs before activating the hyperlink, and then run a custom command. In this example, we open Explorer displaying the path for the current executable file. The OpenLinkEventArgs.Handled property of the event parameter is set to true. This disables subsequent default processing.

To specify the display text for the editor, the RepositoryItemHyperLinkEdit.Caption property is set to a specific string ("Show Startup Directory"). If RepositoryItemHyperLinkEdit.Caption contains a non-empty string, the editor will always display this value in the edit box. This allows you to store specific data in the edit value while representing them using the RepositoryItemHyperLinkEdit.Caption string.

The following image shows a hyperlink editor with a customized caption and Explorer activated by the editor:

Hyperlink_example_ShowStart

hyperLinkEdit1.Properties.Caption = "Show Startup Directory";
// ...
void hyperLinkEdit1_OpenLink(object sender, DevExpress.XtraEditors.Controls.OpenLinkEventArgs e) {
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = Application.StartupPath;
    process.StartInfo.Verb = "explore";
    process.StartInfo.WindowStyle = (sender as HyperLinkEdit).Properties.BrowserWindowStyle;
    process.Start();
    e.Handled = true;
}