Intermediate
8 min read
Control #10
LinkLabel Control
LinkLabel is like a Label that looks and acts like a hyperlink. When clicked, it triggers an action.
What is a LinkLabel?
LinkLabel displays text as a hyperlink (blue, underlined). Clicking it is like clicking a web link. It's perfect for navigation, opening URLs, or triggering actions.
Code Example
// Basic usage - open a website
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://www.google.com");
}
// Multiple links in one LinkLabel
linkLabel1.Text = "Visit our website or contact support";
linkLabel1.Links.Add(6, 7, "https://website.com"); // "website"
linkLabel1.Links.Add(28, 7, "mailto:support@site.com"); // "support"
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url = e.Link.LinkData.ToString();
System.Diagnostics.Process.Start(url);
}
Exercise
Task: Create a help/about page with LinkLabels.
- Add a LinkLabel: "Visit our website".
- Add a LinkLabel: "Email support".
- Add a LinkLabel: "Terms and Conditions" that shows a MessageBox.
- Add a LinkLabel with multiple links in one text.
Key Takeaway
LinkLabel provides a familiar hyperlink experience in Windows Forms. Use it for navigation, opening URLs, and triggering actions.