LinkLabels: link to text file : LinkLabel « GUI Windows Forms « C# / CSharp Tutorial






LinkLabels: link to text file
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());
  }
}








23.26.LinkLabel
23.26.1.LinkLabels: Text property and LinkAreaLinkLabels: Text property and LinkArea
23.26.2.LinkLabels: Add a linkLinkLabels: Add a link
23.26.3.LinkLabels: use generic Add and generic handlerLinkLabels: use generic Add and generic handler
23.26.4.LinkLabels: multiple links and generic handlerLinkLabels: multiple links and generic handler
23.26.5.LinkLabels: link to text fileLinkLabels: link to text file
23.26.6.Add Image in an ImageList to a LinkLabelAdd Image in an ImageList to a LinkLabel