2009-03-01 19 views

回答

7

您可以處理Navigating事件,將WebBrowserNavigatingEventArgs的Cancel屬性設置爲true,並使用Process.Start在IE中打開URL。

事情是這樣的:

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) 
{ 
    // prevents WebBrowser to navigate 
    if (e.Url.Host.Length > 0) // Otherwise the default about:blank when you init the control doesn't work 
    { 
     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(); 
    } 
} 
+2

就像一個魅力 - 差不多。在取消導航之前,我必須檢查e.URL.Host.Length> 0。當我設置網頁瀏覽器控件時,它將導航到「about:blank」,當我取消這個控件時,我無法設置任何文檔文本。 無論如何,我明白了,感謝您的幫助... 歡呼聲 – 2009-03-01 21:58:51

相關問題