Web Design. Development. Optimization. RSS 2.0
 Tuesday, May 18, 2004

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.

 

Tuesday, May 18, 2004 3:05:23 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET
Del.icio.us Digg Technorati Blinklist Furl reddit
Comments are closed.
Archive
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Scott Duffy
Sign In
Statistics
Total Posts: 484
This Year: 44
This Month: 6
This Week: 1
Comments: 76
Themes
Pick a theme:
All Content © 2008, Scott Duffy
DasBlog theme 'Business' created by Christoph De Baene (delarou)