HyperlinkLabelControl Class

The label that supports displaying text or its portion as a hyperlink. Allows you to use HTML tags to format text.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

public class HyperlinkLabelControl :
    LabelControl
Public Class HyperlinkLabelControl
    Inherits LabelControl

Remarks

The HyperlinkLabelControl allows displaying all its text or part of it as a hyperlink.

HyperlinkLabelControlTextProperty HyperlinkLabelControlTextWithHtmlTag

If you specify the control's Text property as an ordinary string, the entire text is considered and displayed as a hyperlink.

hyperlinkLabelControl1.Text = "www.devexpress.com";

To show a part of text as a hyperlink, format this substring with the <href></href> tag. You can also add multiple hyperlinks to the control's text using this tag.

hyperlinkLabelControl2.Text = "Visit our <href=www.devexpress.com>Web-site</href> and see our <href=www.devexpress.com/Support/Documentation/>Documentation</href> to learn more.";
NOTE

In the HyperlinkLabelControl, HTML formatting is always allowed. So, you can use other HTML tags (for instance, <color>, <b>, <size>, <br>, etc.) to format the control's text. See the HTML Text Formatting document for more information.

By default, no actions are performed when an end-user clicks hyperlinks. To process a specific hyperlink or perform other desired actions, handle the HyperlinkLabelControl's LabelControl.HyperlinkClick event.

The following table lists the available states of hyperlinks, and properties affecting the link appearance in corresponding states.

Link State Appearance Property Comments
Normal HyperlinkLabelControlAppearanceObject.LinkColor -
Pressed HyperlinkLabelControlAppearanceObject.PressedColor -
Hovered - Use the HyperlinkLabelControl.LinkBehavior property to specify when links should be underlined (always, never, when the mouse is hovered over links, etc.).
Visited HyperlinkLabelControlAppearanceObject.VisitedColor By default, the control does not mark links as visited links when an end-user clicks them. However, you can manually mark all links as visited links by setting the HyperlinkLabelControl.LinkVisited property to true (for instance, in the HyperlinkClick event handler). Visited links will be highlighted in the corresponding color.
Disabled HyperlinkLabelControlAppearanceObject.DisabledColor Hyperlinks are in the disabled state if the control's Enabled property is set to false.

Since the HyperlinkLabelControl class is derived from the LabelControl class, it inherits all the label control's features, such as the capability to display regular and animated images, the alignment of images relative to the control's text, a horizontal line within the control's empty space, etc. See the LabelControl class description to learn more.

To format text using HTML syntax in cells in container controls (e.g., Data Grid, Tree List, etc.), use the RepositoryItemHypertextLabel in-place editor.

Examples

The following code demonstrates how to use the HyperlinkLabelControl class.

This example creates a HyperlinkLabelControl displaying two hyperlinks. Hyperlinks are inserted to the control's text (Text property) using the <href></href> tag. The HyperlinkClick event handler opens the clicked link in the Web browser, and marks all links as visited links.

To underline links only when the mouse is hovered over them, the HyperlinkLabelControl.LinkBehavior property is set to HoverUnderline. The HyperlinkLabelControlAppearanceObject.LinkColor, HyperlinkLabelControlAppearanceObject.PressedColor and HyperlinkLabelControlAppearanceObject.VisitedColor properties specify the colors used to paint hyperlinks in various states.

HyperlinkLabelControlExampleLinkStates

using DevExpress.XtraEditors;

//...

private HyperlinkLabelControl hyperlinkLabelControl;

private void Form1_Load(object sender, EventArgs e) {
    hyperlinkLabelControl = new HyperlinkLabelControl();
    this.Controls.Add(hyperlinkLabelControl);

    // Specify the control's name and location.
    hyperlinkLabelControl.Name = "hyperlinkLabelControl";
    hyperlinkLabelControl.Location = new System.Drawing.Point(5, 5);
    // Specify the control's text with two hyperlinks. Format the text using the <href></href> and <br> HTML tags.
    hyperlinkLabelControl.Text = "Visit our <href=www.devexpress.com>Web-site</href><br>" +
        "See our <href=www.devexpress.com/Support/Documentation/>Documentation</href>";
    // Allow the control's text to be wrapped.
    hyperlinkLabelControl.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
    // Set the behavior of the links. They will display underline text only when the mouse is hovered over the links. 
    hyperlinkLabelControl.LinkBehavior = LinkBehavior.HoverUnderline;
    // Specify the appearance settings of the links.
    hyperlinkLabelControl.Appearance.LinkColor = System.Drawing.Color.Blue;
    hyperlinkLabelControl.Appearance.VisitedColor = System.Drawing.Color.Navy;
    hyperlinkLabelControl.Appearance.PressedColor = System.Drawing.Color.Violet;
    // Add an event handler to do specific actions when a specific link is clicked.
    hyperlinkLabelControl.HyperlinkClick += new DevExpress.Utils.HyperlinkClickEventHandler(hyperlinkLabelControl_HyperlinkClick);
}

private void hyperlinkLabelControl_HyperlinkClick(object sender, DevExpress.Utils.HyperlinkClickEventArgs e) {
    // Mark the links as visited links.
    hyperlinkLabelControl.LinkVisited = true;
    System.Diagnostics.Process.Start(e.Link);
}
See Also