Updated: July 2008
Represents a Windows label control that can display hyperlinks.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The control is similar to a Label control with the exception that it can display a hyperlink. Multiple hyperlinks can be specified in the text of the control. Each hyperlink can perform a different task within an application. For example, you can use a hyperlink to display a Web site in Microsoft Internet Explorer or to load a log file associated with an application.
Each hyperlink displayed in the control is an instance of the LinkLabel.Link class. The LinkLabel.Link class defines display information, state, and location of the hyperlink. In addition, the LinkData property of the LinkLabel.Link class enables you to associate information, such as a URL to display, with the hyperlink. When a user clicks a hyperlink within the control, the LinkClicked event is raised, and the LinkLabel.Link object representing the hyperlink that was clicked is passed as part of the LinkLabelLinkClickedEventArgs object that is passed as a parameter to the event handler. You can use this object to obtain the LinkLabel.Link object associated with the hyperlink that was clicked by the user. All hyperlinks contained within the control are stored in the LinkLabel.LinkCollection class instance for the control.
There are two ways to add a hyperlink to the control. The quickest way is to specify a LinkArea and assign it to the LinkArea property. This enables you to specify a single hyperlink within the text of the control. To add multiple hyperlinks, you can use the Add method of the LinkLabel.LinkCollection class by accessing the collection through the Links property.
When a control is created, a default hyperlink that contains all the text within the control is added to the LinkLabel.LinkCollection. You can override this default link by specifying a new link area with the LinkArea property, or specify a link using the Add method of the LinkLabel.LinkCollection. You can also remove the default hyperlink by using the Remove method of the LinkLabel.LinkCollection class.
The class inherits the TabStop property from the Label class. The TabStop property is true by default, as long as there is at least one link of greater than zero length in the Links collection. The control has a single TabIndex value. However, each link of greater than zero length gets its own tab stop, in left-to-right order. To prevent tab navigation to the control, set the TabStop property to false. However, be aware that adding new links to the Links collection will automatically set the TabStop property to true again.
The provides a number of properties that enable you to define the display appearance of hyperlinks in the control. The ActiveLinkColor, DisabledLinkColor, LinkColor, and VisitedLinkColor properties define the colors used when displaying a hyperlink in various states. The LinkBehavior property defines the display of the underline that is associated with a hyperlink.
The following example demonstrates using the class. The example handles the LinkClicked event by opening a Web site.
The following example demonstrates using the class, with multiple LinkArea sections defined, to display a label on a form. The example demonstrates setting the AutoSize, LinkBehavior, DisabledLinkColor, LinkColor, and VisitedLinkColor properties to customize the look of the . The first LinkArea is specified using the LinkLabel.LinkArea property. Additional links are added to the using the LinkLabel.LinkCollection.Add method. The example handles the LinkClicked event by starting the Web browser for hyperlinks, and displaying a MessageBox for other links.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.