The LinkLabel class provided in System.Windows.Forms is nice, especially when the entire Text of the control is the hyperlink. Unfortunately, things get a bit harrier when the link is a subset of the text. If you want multiple links in the control, it really gets messy and you need to create the links programmatically. Not only that, you need to manually wire in a handler, usually to launch a web page. Who needs that?
HtmlLinkLabel is a subclass of LinkLabel that takes a string (via the TextHtml property) with embedded HTML anchor tags ("<a/>"). When the user clicks a link, System.Diagnostics.Process.Start(string) is called with the text in the "href" attribute passed as the parameter.
If you would like to have the click do something other than start a process, you can subclass HtmlLinkLabel and override OnLinkClicked. The Link property of LinkLabelLinkClickedEventArgs contains a property called LinkData that references an HtmlLinkLabel.HtmlLinkLabelInfo object. The HtmlLinkLabel.HtmlLinkLabelInfo contains three properties: Href, Text and Index. The first two are self-explanatory and the third is the order of occurance of the link in the text. The index is only of interest if you can't key off of the href or text because you have two or more controls with the same href and text.
Here is an example of the standard handling:
link.TextHtml = "go to <a href=\"www.sliver.com\">sliver</A> or start <a href=\"notepad.exe\">notepad</a>.";
The above results in, which will brind up www.sliver.com or Notepad, respectively:
Back to dotnet