It’s common in web programming to place links to resources on a page. The hyperlink tag is on nearly every page on your website. But what about Windows Forms?
In .NET it is easy to add a hyperlink to a form. At least it looks and acts like a hyperlink.
- Add a LinkLabel to the form.
- Change the text to the web address (example http://www.waltritscher.com/ )
- In the LinkClicked event add one line of code.
1: Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
2: Process.Start(LinkLabel1.Text)
3:
4: End Sub
This works because Windows knows that a string with http:// is a web address and will launch the users default web browser. Process.Start merely asks Windows to launch a process based on the file/URL string being passed as parameter.
Comments
I am teaching myself how to program MS Visual Basic 2005 and creating a database and wanted to place a hyperlink on it directing users to my company web site and I been reading and searching how to do this for days and finally I’ve come across your site and it worked. A simple 3 liner. Thanks a bunch. Brian