LinkLabel.Links.IndexOf
using System;
using System.Drawing;
using System.Windows.Forms;
public class LinkLabelLinkToAFile : Form {
public LinkLabelLinkToAFile(){
Size = new Size(300,250);
LinkLabel lnkTxtFile = new LinkLabel();
lnkTxtFile.Parent = this;
lnkTxtFile.Text = "Address";
lnkTxtFile.Location = new Point(0,100);
lnkTxtFile.AutoSize = true;
lnkTxtFile.BorderStyle = BorderStyle.None;
lnkTxtFile.LinkBehavior = LinkBehavior.NeverUnderline;
lnkTxtFile.ActiveLinkColor = Color.Green;
lnkTxtFile.LinkColor = Color.Red;
lnkTxtFile.VisitedLinkColor = Color.Orange;
lnkTxtFile.Links.Add(0,lnkTxtFile.Text.ToString().Length,@"c:\test.txt");
lnkTxtFile.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(lnkGeneric_LinkClicked);
}
static void Main()
{
Application.Run(new LinkLabelLinkToAFile());
}
private void lnkGeneric_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
LinkLabel lnk = new LinkLabel();
lnk = (LinkLabel)sender;
lnk.Links[lnk.Links.IndexOf(e.Link)].Visited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
Related examples in the same category