如何从默认Web浏览器中触发WebBrowserDocumentCompleted事件

时间:2017-12-18 11:08:37

标签: c# browser webbrowser-control

我尝试了两种方法:

  1. wb.Navigate(Url,true);当我使用此网络浏览器时,但WebBrowserDocumentCompleted事件在页面加载后不会触发。
  2. wb.Navigate(Url);当我使用此WebBrowserDocumentCompleted事件时,但是浏览器未出现在屏幕上。如何在同一时间显示外部浏览器并触发WebBrowserDocumentCompleted事件?

    private void button1_Click(object sender, EventArgs e)
    {
        System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
        wb.DocumentCompleted += WebBrowserDocumentCompleted;
        wb.Visible = true;
        wb.ScrollBarsEnabled = false;
        wb.ScriptErrorsSuppressed = true;
        wb.Navigate("http://www.google.com",true);
    }
    
    private void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if ((sender as WebBrowser).ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete)
        {
            // Do what ever you want to do here when page is completely loaded.
        }
    }
    

0 个答案:

没有答案