为什么WebBrowser_DocumentCompleted()射击两次? [英] Why is WebBrowser_DocumentCompleted() firing twice?

查看:269
本文介绍了为什么WebBrowser_DocumentCompleted()射击两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我用一个简单的WebBrowser控件来浏览网页,所以我需要改变窗体的文本,而这样做。我使用 -

Well, I'm using a simple webbrowser control to browse to a page, so I need to change the Text of the form while doing so. I'm using -

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
     this.Text += " - " + webBrowser1.Document.Domain;
}

但使用断点,我注意到,这一事件被解雇两次。我甚至尝试 _Navigated()事件。这也触发了两次。得到的标题韦伯 - google.co.in - google.co.in ..

but using a breakpoint, i noticed that, this event is firing twice. I even tried _Navigated() event. it also fired twice. Resulting the title to "Webber - google.co.in - google.co.in" ..

我也注意到,本次活动数次在加载msn.com ..我试图改变只有当页面完成加载完全形式的文本。

I also noticed that this event fired several times while loading msn.com.. I'm trying to change the text of the form only when the page has finished loading totally..

任何补救措施?

推荐答案

您可以检查时,在事件被触发的WebBrowser.ReadyState:

You can check the WebBrowser.ReadyState when the event is fired:

if (browser.ReadyState != WebBrowserReadyState.Complete)
    return;

readyState的将被设置为完成一次整个文件已准备就绪。

ReadyState will be set to Complete once the whole document is ready.

这篇关于为什么WebBrowser_DocumentCompleted()射击两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆