C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Info: The Form1_Load method is executed when the program begins. At this stage, we create a new Link element.
Tip: Link elements are stored in the Links collection on a LinkLabel instance. We call the Add method to store the LinkLabel.
Object: The LinkData reference is of an object type—you can store anything there and use it through casting.
LinkClicked: We simply store a string in the location and then, in LinkClicked, we access the Link.LinkData from the parameter "e" and cast it.
Example that uses LinkLabel: C#
using System.Diagnostics;
using System.Windows.Forms;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Add a link to the LinkLabel.
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://www.dotnetCodex.com/";
linkLabel1.Links.Add(link);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Send the URL to the operating system.
Process.Start(e.Link.LinkData as string);
}
}
}
Tip: Using the Links collection, you can create multiple links in the same text.
TextAnd: The visited link color appears once the link has been previously clicked. This is often purple.
Tip: You should specify the lexical position of the links. We do this by specifying the index of the start and the length in characters.
Then: In LinkClicked, you can acquire the LinkData from the clicked link in the same way as in the example shown.