瀏覽器的錯誤處理

基礎篇

C# 簡介

開發環境

變數與運算

流程控制

陣列

函數

物件

例外處理

函式庫篇

檔案處理

資料結構

正規表達式

Thread

應用篇

視窗程式

媒體影音

網路程式

遊戲程式

手機程式

資料庫

雲端運算

特殊功能

委派

擴展方法

序列化

LinQ

WPF

網路資源

教學影片

投影片

教學文章

軟體下載

考題解答

101習題

來源文件:Stackoverflow:Can I detect errors while using a .Net WebBrowser control?

The WebBrowser windows forms control is wrapper around Internet Explorer and it doesn't expose all the functionality of the underlying ActiveX control and particularly the NavigateError event. Here's a workaround:

First add reference to SHDocVw.dll to your project (COM tab of Add Reference window). Then you can do the following to capture errors:

private void button1_Click(object sender, EventArgs e)
{
    SHDocVw.WebBrowser instance = 
(SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
    instance.NavigateError += 
new SHDocVw.DWebBrowserEvents2_NavigateErrorEventHandler(instance_NavigateError);
    webBrowser1.Navigate("http://www.google.com/foo");
}

void instance_NavigateError(object pDisp, ref object URL, 
  ref object Frame, ref object StatusCode, ref bool Cancel)
{
    // Do whatever you want with the error            
}

參考文獻

  1. Stackoverflow:Can I detect errors while using a .Net WebBrowser control?
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License