Let us look at a simple C# Windows Forms LinkLabel example.
Example 1: LinkLabel
This example will comprise the following files:
LinkLabel.cs
Step 1: Create Project
- The first step is to create a C# Project.
- Go to
FILE-->New-->Project
to create a new project.
Step 2: Write Code
Write Code as follows:
*(a). LinkLabel.cs
Create a file named LinkLabel.cs
Here is the full code
using System;
using System.Windows.Forms;
namespace Examples {
class MainForm : Form {
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
public MainForm() {
Text = "LinkLabel example";
label1.Parent = this;
label1.Text = "Gammasoft present CSharp examples";
label1.AutoSize = true;
label1.Location = new System.Drawing.Point(10, 10);
label1.Links.Add(new LinkLabel.Link(0, 9, "https://gammasoft71.wixsite.com/gammasoft"));
label1.Links.Add(new LinkLabel.Link(18, 6, "https://gammasoft71.wixsite.com/gammasoft/csharp"));
label1.LinkClicked += delegate(object sender, LinkLabelLinkClickedEventArgs e) {
e.Link.Visited = true;
System.Diagnostics.Process.Start(e.Link.LinkData as string);
};
}
private LinkLabel label1 = new LinkLabel();
}
}
Run
Simply copy the source code into your C# Project,Build and Run. Alternatively download the code using the links provided below, then open the .csproj
project, build and run.
Reference
Download the code using the below links:
Number | Link |
---|---|
1. | Download Example |
2. | Follow code author |