System.Windows.Forms.LinkLabel Class

Represents a Windows label control that can display hyperlinks.

See Also: LinkLabel Members

Syntax

[System.ComponentModel.ToolboxItem("System.Windows.Forms.Design.AutoSizeToolboxItem,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.ComponentModel.DefaultEvent("LinkClicked")]
public class LinkLabel : Label, IButtonControl

Remarks

The System.Windows.Forms.ToolStripLabel control replaces and adds functionality to the System.Windows.Forms.Label and System.Windows.Forms.LinkLabel controls. However, the System.Windows.Forms.Label and System.Windows.Forms.LinkLabel controls are retained for both backward compatibility and future use, if you choose.

The System.Windows.Forms.LinkLabel control is similar to a System.Windows.Forms.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 System.Windows.Forms.LinkLabel control is an instance of the System.Windows.Forms.LinkLabel.Link class. The System.Windows.Forms.LinkLabel.Link class defines display information, state, and location of the hyperlink. In addition, the System.Windows.Forms.LinkLabel.Link.LinkData property of the System.Windows.Forms.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 LinkLabel.LinkClicked event is raised, and the System.Windows.Forms.LinkLabel.Link object representing the hyperlink that was clicked is passed as part of the System.Windows.Forms.LinkLabelLinkClickedEventArgs object that is passed as a parameter to the event handler. You can use this object to obtain the System.Windows.Forms.LinkLabel.Link object associated with the hyperlink that was clicked by the user. All hyperlinks contained within the System.Windows.Forms.LinkLabel control are stored in the System.Windows.Forms.LinkLabel.LinkCollection class instance for the control.

There are two ways to add a hyperlink to the System.Windows.Forms.LinkLabel control. The quickest way is to specify a System.Windows.Forms.LinkArea and assign it to the LinkLabel.LinkArea property. This enables you to specify a single hyperlink within the text of the control. To add multiple hyperlinks, you can use the System.Windows.Forms.LinkLabel.LinkCollection.Add(int, int) method of the System.Windows.Forms.LinkLabel.LinkCollection class by accessing the collection through the LinkLabel.Links property.

When a System.Windows.Forms.LinkLabel control is created, a default hyperlink that contains all the text within the System.Windows.Forms.LinkLabel control is added to the System.Windows.Forms.LinkLabel.LinkCollection. You can override this default link by specifying a new link area with the LinkLabel.LinkArea property, or specify a link using the System.Windows.Forms.LinkLabel.LinkCollection.Add(int, int) method of the System.Windows.Forms.LinkLabel.LinkCollection. You can also remove the default hyperlink by using the System.Windows.Forms.LinkLabel.LinkCollection.Remove(System.Windows.Forms.LinkLabel.Link) method of the System.Windows.Forms.LinkLabel.LinkCollection class.

The Label.TabStop property is true by default, as long as there is at least one link of greater than zero length in the LinkLabel.Links collection. The System.Windows.Forms.LinkLabel control has a single Control.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 System.Windows.Forms.LinkLabel control, set the Label.TabStop property to false. However, be aware that adding new links to the LinkLabel.Links collection will automatically set the Label.TabStop property to true again.

The System.Windows.Forms.LinkLabel provides a number of properties that enable you to define the display appearance of hyperlinks in the control. The LinkLabel.ActiveLinkColor, LinkLabel.DisabledLinkColor, LinkLabel.LinkColor, and LinkLabel.VisitedLinkColor properties define the colors used when displaying a hyperlink in various states. The LinkLabel.LinkBehavior property defines the display of the underline that is associated with a hyperlink.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0