windowsforms-devexpress-dot-xtraeditors-a4f364fb.md
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.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXLicenseWinFormsEditors]
public class HyperlinkLabelControl :
LabelControl
<DXLicenseWinFormsEditors>
Public Class HyperlinkLabelControl
Inherits LabelControl
The HyperlinkLabelControl displays its text (or part of it) as a hyperlink.
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";
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.";
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."
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.
DevExpress controls support regular and super tooltips. Enable the ShowToolTips option to display tooltips when the mouse pointer hovers over the control.
Customize Regular Tooltip Text
Use the following properties of the target control to specify regular tooltip text and title:
|
API
|
Description
| | --- | --- | |
|
Specifies tooltip text. You can use line breaks in regular tooltips.
| |
|
Specifies whether to parse HTML tags in text.
| |
|
Specifies the tooltip title. If you do not specify tooltip text, the tooltip is not displayed even if you specify the title.
|
The following code snippet specifies tooltip text and title for a TextEdit editor:
public Form1() {
InitializeComponent();
textEdit1.ShowToolTips = true;
textEdit1.ToolTipTitle = "Name";
textEdit1.ToolTip = "Please enter your name";
}
Public Sub New()
InitializeComponent()
textEdit1.ShowToolTips = True
textEdit1.ToolTipTitle = "Name"
textEdit1.ToolTip = "Please enter your name"
End Sub
Private Sub ToolTipController1_BeforeShow(ByVal sender As Object, ByVal e As ToolTipControllerShowEventArgs)
Dim controller As ToolTipController = TryCast(sender, ToolTipController)
If e.ToolTip = textEdit1.ToolTip Then
e.ImageOptions.SvgImage = (TryCast(controller.ImageList, SvgImageCollection))("personalCard")
End If
End Sub
Assign an Image to Regular Tooltips
Use the control’s ToolTipIconType property to assign a predefined icon. The ToolTipController.IconSize property specifies icon size.
Assign a custom image as follows:
Note
The ToolTipIconType property has priority over e.ImageOptions. If you assign a custom image, set ToolTipIconType to None.
The following code snippet assigns a custom image to the TextEdit tooltip:
Note
textEdit1, toolTipController1, and svgImageCollection1 were created at runtime.
public Form1() {
InitializeComponent();
textEdit1.ShowToolTips = true;
textEdit1.ToolTipTitle = "Name";
textEdit1.ToolTip = "Please enter your name";
textEdit1.ToolTipController = toolTipController1;
toolTipController1.ImageList = svgImageCollection1;
toolTipController1.BeforeShow += ToolTipController1_BeforeShow;
}
private void ToolTipController1_BeforeShow(object sender, ToolTipControllerShowEventArgs e) {
ToolTipController controller = sender as ToolTipController;
if (e.ToolTip == textEdit1.ToolTip)
e.ImageOptions.SvgImage = (controller.ImageList as SvgImageCollection)["personalCard"];
}
Public Sub New()
InitializeComponent()
textEdit1.ShowToolTips = True
textEdit1.ToolTipTitle = "Name"
textEdit1.ToolTip = "Please enter your name"
textEdit1.ToolTipController = toolTipController1
toolTipController1.ImageList = svgImageCollection1
AddHandler toolTipController1.BeforeShow, AddressOf ToolTipController1_BeforeShow
End Sub
Private Sub ToolTipController1_BeforeShow(ByVal sender As Object, ByVal e As ToolTipControllerShowEventArgs)
Dim controller As ToolTipController = TryCast(sender, ToolTipController)
If e.ToolTip = textEdit1.ToolTip Then
e.ImageOptions.SvgImage = (TryCast(controller.ImageList, SvgImageCollection))("personalCard")
End If
End Sub
Display a Super Tooltip
Use the control’s SuperTip property to assign a super tooltip. If you wish to use HTML tags in a super tooltip, enable the SuperToolTip.AllowHtmlText property.
Setting the ToolTipController.ToolTipType property to SuperTip converts existing regular tooltips to super tooltips.
Tip
Read the following help topic for information on how to customize super tooltips: Hints and Tooltips.
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.
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
HTML tags.
hyperlinkLabelControl.Text = "Visit our <href=www.devexpress.com>Web-site</href>
" +
"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);
}
Imports DevExpress.XtraEditors
'...
Private hyperlinkLabelControl As HyperlinkLabelControl
Private Sub Form1_Load(sender As Object, e As EventArgs)
hyperlinkLabelControl = New HyperlinkLabelControl()
Me.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
HTML tags.
hyperlinkLabelControl.Text = "Visit our <href=www.devexpress.com>Web-site</href>
" + "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(AddressOf hyperlinkLabelControl_HyperlinkClick)
End Sub
Private Sub hyperlinkLabelControl_HyperlinkClick(sender As Object, e As DevExpress.Utils.HyperlinkClickEventArgs)
' Mark the links as visited links.
hyperlinkLabelControl.LinkVisited = True
System.Diagnostics.Process.Start(e.Link)
End Sub
Object MarshalByRefObject Component Control DevExpress.XtraEditors.XtraControl ControlBase BaseControl BaseStyleControl LabelControl HyperlinkLabelControl
See Also