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.v24.2.dll
NuGet Package: DevExpress.Win.Navigation
#Declaration
public class HyperlinkLabelControl :
LabelControl
#Remarks
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.
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.";
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 | Hyperlink |
- |
Pressed | Hyperlink |
- |
Hovered | - | Use the Hyperlink |
Visited | Hyperlink |
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 Hyperlink |
Disabled | Hyperlink |
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.
#Tooltips
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";
}
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:
- Create a ToolTipController and assign it to the control’s ToolTipController property.
- Create an image collection and assign it to the ToolTipController.ImageList property.
- Handle the ToolTipController.BeforeShow event. Use the e.ImageOptions parameter to assign a raster or vector image to the tooltip.
Note
The Tool
property has priority over e.
. If you assign a custom image, set Tool
to None
.
The following code snippet assigns a custom image to the TextEdit
tooltip:
Note
text
, tool
, and svg
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"];
}
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.
#Example
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 <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);
}