Is it possible to open a LinkLabel in the default computers web browser?
Asked
Active
Viewed 3.5k times
31
-
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
54
yes - you can use System.Diagnostics.Process.Start(url) in the "link clicked" event.
Cheeso
- 184,848
- 97
- 460
- 704
-
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,480
- 7
- 46
- 68
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,108
- 1
- 17
- 25
1
Try this solution it is better:
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(((LinkLabel)sender).Text);
}
Miss Chanandler Bong
- 3,817
- 10
- 26
- 35
Mikaël Derain
- 11
- 1