Visual C#

Windows Controls: The Link Label

In the past, to add an internet or email link to a form, there were many steps to follow. As the internet and email had become an integral part of the…

1 min read326 words1 code sample

Introduction#

Previously, adding an internet or email link to a form was a multi-step process. As these links became cultural staples, a dedicated control was needed. The .NET Framework addressed this by introducing the LinkLabel control, while keeping the original behavior intact.

As its name indicates, the LinkLabel control allows you to create a link. If you have done web development, you would know that a link can more readily be made fancy by varying its colors. A link typically uses three different colors (actually, if you use cascading style sheet, you can add a fourth color as hover): while keeping the original behavior intact.

  • Link: This is the general color used on a link that a user has not clicked before. The LinkLabel class defines this color through the LinkColor property.
  • Active Link: When the user clicks a link, its target typically opens if everything is alright. This causes the link to change its color status. The color of an active link is represented in the LinkLabel class with the ActiveLinkColor property.
  • Visited: When a user comes to a page or the document that provides a link, you can indicate whether the link was previously accessed or not. This is done by displaying a color other than the link color. The color of a previously visited link is represented in the LinkLabel class by the VisitedLinkColor property.

Once a link is created, you can specify how it appears when accessed, such as whether it underlines when hovered over. These interactions are managed by the LinkBehavior property, which offers options like AlwaysUnderline, HoverUnderline, NeverUnderline, or follows system settings from the Internet Options dialog. Links generally facilitate navigation to other pages or documents. There may be times when a link should be non-clickable; in these instances, you can disable it. The DisabledLinkColor property allows you to set or retrieve the color of a disabled link. For example:

C#
private void linkLabel1_LinkClicked(object sender,
            LinkLabelLinkClickedEventArgs e)
{
        System.Diagnostics.Process.Start(
    		@"C:\Program Files\Internet Explorer\iexplore.exe",
        		"http://www.functionx.com/vccli");
}

Home Copyright © 2010-2011 C#Key