One of the things I wanted to do for the dasBlog Log Analyzer I recently developed was add a link to my web site from the main screen. It's fairly common these days to have URL's embedded in Windows applications, that cause the browser to open to the appropriate web site when clicked.
This functionality is not fully implemented in the IDE using the System.Windows.Forms.LinkLabel control built into Visual Studio .NET. When I first implemented this control, I looked for a property of the LinkLabel control that would allow me to add a URL. No such luck. Instead, you have to write some code to activate the link as a URL. Here's how you do that.
1. First, import a new namespace at the top of your project code:
Imports System.Diagnostics
2. Next, add a LinkLabel control to your form. I named mine lblURL.
3. Next, add the following two lines of code to the form Load event handler. Of course, if your form does not have an event handler, create one by double-clicking on the form background in the form designer.
lblURL.Links.Remove(lblURL.Links(0))
lblURL.Links.Add(0, lblURL.Text.Length,
"http://www.mydemos.com/Blog")
4. Next, create an event handler for the lblURL control by double-clicking on the LinkLabel control.
5. Finally, add the following two lines of code to the event handler you just created:
Dim sInfo As New ProcessStartInfo(e.Link.LinkData.ToString())
Process.Start(sInfo)
What does this all do? Well, the Add method of the LinkLabel control creates the LinkLabel text using the URL of the destination web site. And the event handler of the linklabel starts the program associated with URL's in Windows, most likely Internet Explorer.
What a beautiful and elegant implementation.
Based on MSDN Support article 320320.