Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to use Link Label Control in C# (.net).

Author: Zunnair
Download Source Code : 881_source.zip

In this article you will learn that how we can use Link Label Control in C# and VB applications.

 Link label is control provided by dot net. This control is very use full in different windows application.

The Link Label control is used to execute the links of other files and web pages. Link Label is a class which is derived from label class so it has all the functions of label class. It works like a hyperlink. The link can change color to indicate whether the link is new, visited or active. When clicked, the Link Label generates a Link Clicked event.

Properties of Link Label:

Text:  

Denotes the text to show on the control.

Link Area:

Denotes which part of text in the Link Label is treated as element of the link.

Links:

 Lists the Link Label Link objects, which are the links enclosed in the Link Label.

Link Visited:

 If true, link appears as though it were visited (its color is changed to that specified by property Visited Link Color).

Visited Link Color:

 Denotes the color of visited links. Default is purple.

Active Link Color:

Show the color of the active link when clicked. Default color is red.

 Link Color:

          Denotes the original color of every links prior to they have been visited. Default color is blue.

.
Link Clicked:

  Generated when link is clicked.

Now let us see the usage of Link Label control with an example:

C#

partial class Form1

    {

        ///

        /// Required designer variable.

        ///

        private System.ComponentModel.IContainer components = null;

 

        ///

        /// Clean up any resources being used.

        ///

        /// true if managed resources should be disposed; otherwise, false.

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }

 

        #region Windows Form Designer generated code

 

        ///

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        ///

        private void InitializeComponent()

        {

            this.linkLabel1 = new System.Windows.Forms.LinkLabel();

            this.SuspendLayout();

            //

            // linkLabel1

            //

            this.linkLabel1.AutoSize = true;

            this.linkLabel1.Location = new System.Drawing.Point(165, 123);

            this.linkLabel1.Name = "linkLabel1";

            this.linkLabel1.Size = new System.Drawing.Size(87, 13);

            this.linkLabel1.TabIndex = 24;

            this.linkLabel1.TabStop = true;

            this.linkLabel1.Text = "www.devasp.net";

            this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);

            //

            // Form1

            //

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(804, 585);

            this.Controls.Add(this.linkLabel1);

            this.Name = "Form1";

            this.Text = "Form1";

            this.Load += new System.EventHandler(this.Form1_Load);

            this.ResumeLayout(false);

            this.PerformLayout();

 

        }

 

        #endregion

 

        private System.Windows.Forms.LinkLabel linkLabel1;

 

    }

We write the string in text which we want to show the user. When the user click on the link, Link clicked event is occurred and the web page is opened and navigates to the specified address.

To demonstrate make a windows application. Drag link label control on form. Click on the label.

Now write the following code on Link clicked event

C#

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

  {

    System.Diagnostics.Process.Start("IExplore", "http://www.devasp.net");

    linkLabel1.LinkColor = Color.Black;

    linkLabel1.LinkVisited = true;

  }

VB

Private Sub linkLabel1_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs)

        System.Diagnostics.Process.Start("IExplore", "http://www.devasp.net")

        linkLabel1.LinkColor = Color.Black

        linkLabel1.LinkVisited = True

    End Sub

This simple code opens the link.

To set the properties of the Link Label at run time. Write the code in load event.

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "Devasp.Net Application";

            linkLabel1.Text = "www.devasp.net";

            LinkArea obj=new LinkArea(0,14);

            linkLabel1.LinkArea = obj;

            linkLabel1.LinkColor = Color.DarkRed;

            linkLabel1.LinkVisited = false;

        }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "Devasp.Net Application"

        linkLabel1.Text = "www.devasp.net"

        Dim obj As New LinkArea(0, 14)

        linkLabel1.LinkArea = obj

        linkLabel1.LinkColor = Color.DarkRed

        linkLabel1.LinkVisited = False

    End Sub

This simple article tells how we can use Link Label Control in C# and VB applications.

Article Comments
how to change the label color a runtime in web application with c#,java,V.B
send coding my email address

Posted on 4/24/2010 10:29:31 PM by RajeevKanojia

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Date Time Conversion in different formats (long time sting, OA date, short date string, short date string, universal time) using “Date Time” ” Class” in C# (.net 2.0) Part 2.

Disclaimer - Privacy
© 2002-2017 DevASP.net