views:

769

answers:

1

I think the title covers it all. I use the control to display some basic HTML with some markups and there are maybe also links in there. What I want to do, is to force clicking on any link to get this link opened in a new IE window instead of navigating to that page in the control itself.

Any idea?

+2  A: 

You can handle the Navigating event, set the Cancel property of WebBrowserNavigatingEventArgs to true, and use Process.Start to open the URL in IE.

Something like this:

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    // prevents WebBrowser to navigate
    e.Cancel = true;

    // Open the URL in an IE window 
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = e.URL.ToString();
    process.Start();
}
Jorge Villuendas
works like a charm - almost. I had to check if the e.URL.Host.Length > 0 before I cancel the navigating. When I setup the webbrowser control it will navigate to "about:blank" and when I cancel this one, I cannot set any document text. Anyway, I got it, thanks to your help...cheers
Stefan Koell