Label Control is used to display some information to the user. Whereas Link label Control is used to give a link to another hyperlink in windows forms and also used to display information.
Steps
Follow the steps below to know how to use label and link label.
Open the Visual Studio 2013 (or whatever the version you have).
Go to File menu -> New -> Project.
Select the Visual C# -> Windows Desktop -> Windows Form Application.
Give the Name as per requirement.
Click on OK button.
Then the Windows Application will be opened.
Now Drag and Drop the Label Control on to form as shown in the below figure.
Now see the properties window shown in the above figure.
Select the label control. Then properties window shows the properties of the label control.
Give the Name as lblName.
Give the Text which need to display like "WELCOME TO SPLESSONS TUTORIAL".
Then the window looks like below figure.
Now drag and drop the Link Label Control on to form.
Give the Name as per requirement and also give the Text.
See the difference between Label and link label control. Link Label Control is in blue color with underline whereas label control is in black with no underline mark.
See the difference between Label Control and Link Label Control in the below figure.
Note
To give links using Link Label Control, c# code has to be written. There is no property for giving links in the properties window.
Giving a link to a Link Label Control
Description
Write the following C# code in the Form1.cs file.
There are two types of files which we have to know.
Form1.cs File: This file is used to write C# code. All the C# code must be written which writes for functionality in this file only.
Form1.Designer.csFile: This is used for designing the form. When the code is dragged an dropped, automatically the designer code will be generated in this file.
Double Click on the form, then the Load event is raised in form1.cs file.
Double Click on the Link Label Control to raise the LinkClicked event.
Write the below code under Load event and LinkClicked event.
[csharp]
private void Form1_Load(object sender, EventArgs e)
{
LinkLabel.Link link = new LinkLabel.Link();//Creates a link
link.LinkData = "http://www.splessons.com/";
//URL that which we want to go
lnklblSPlessons.Links.Add(link);
//Adds the link which we have given above to our link label
}
private void lnklblSPlessons_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.splessons.com/");
//After click on the link label, opens our URL on the browser
}
[/csharp]
Press F5 to run the application. Then the following window will appear.
Click on the Link label then it opens "www.splessons.com" on the browser. One can also change the appearance of Label and Link Label Controls by using properties window. This is all about Label and Link Label Control.