Is it possible to open a LinkLabel
in the default computers web browser?
Asked
Active
Viewed 3.9k times
32
-
1well it's the default behavior once you have set a proper valid url. What kind of problem are you having and how does your code look like so far? – Davide Piras Aug 22 '11 at 22:18
-
1I was looking in the Properties for something that would start it. Originally I tried just setting a url address to the .Text property and of course that didn't work. – acctman Aug 22 '11 at 22:32
-
i don't understand the existence of this control, probably because i do don understand how to use it – beppe9000 Jan 26 '16 at 19:28
4 Answers
55
yes - you can use System.Diagnostics.Process.Start(url)
in the "link clicked" event.

Cheeso
- 189,189
- 101
- 473
- 713
-
1so something like this private void linkSubmit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start(linkSubmit.text as String); } – acctman Aug 22 '11 at 22:35
-
-
11
I always use them like this. This way you will get the default browser to open the URL.
ProcessStartInfo sInfo = new ProcessStartInfo("http://www.google.com");
Process.Start(sInfo);

Tys
- 3,592
- 9
- 49
- 71
10
Here's a solution inspired by MSDN that works without hardcoding the URL into your code:
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url;
if (e.Link.LinkData != null)
url = e.Link.LinkData.ToString();
else
url = linkLabel1.Text.Substring(e.Link.Start, e.Link.Length);
if (!url.Contains("://"))
url = "https://" + url;
var si = new ProcessStartInfo(url);
Process.Start(si);
linkLabel1.LinkVisited = true;
}
You can then easily use LinkArea to have un-hyperlinked text around the link.

eug
- 1,118
- 1
- 16
- 25
2
Try this solution it is better:
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(((LinkLabel)sender).Text);
}

Miss Chanandler Bong
- 4,081
- 10
- 26
- 36

Mikaël Derain
- 21
- 1
-
Agreed - code reuse using the sender object beats a dedicated handler per link/control. – SteveCinq Aug 04 '22 at 16:20