Pregunta

Is it possible to open a LinkLabel in the default computers web browser?

¿Fue útil?

Solución

yes - you can use System.Diagnostics.Process.Start(url) in the "link clicked" event.

Otros consejos

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);

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.

Try this solution it is better:

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    System.Diagnostics.Process.Start(((LinkLabel)sender).Text);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top