如何等到 WebBrowser 在 VB.NET 中完全加载? [英] How to wait until WebBrowser is completely loaded in VB.NET?

查看:39
本文介绍了如何等到 WebBrowser 在 VB.NET 中完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 VB.NET 应用程序中使用 WebBrowser 控件来加载几个 URL (~10-15) 并将它们的 HTML 源代码保存在一个文本文件中.但是,我的代码没有编写当前页面的源代码,而是初始页面的源代码,因为它甚至在页面加载之前就被触发了.

I am using the WebBrowser control in my VB.NET application to load a few URLs ( ~10-15) and save their HTML source in a text file. However, my code doesn't write the source of the current page rather the initial one because the it is triggered even before the page is loaded.

如何在调用任何事件之前等待页面完全加载?

How can I wait until the page is completely loaded before calling any event?

我尝试了以下代码,但不起作用.

I tried the following code but it doesn't work.

Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
   Application.DoEvents()
Loop

推荐答案

听起来您想了解 DocumentCompleted 事件.

Sounds like you want to catch the DocumentCompleted event of your webbrowser control.

MSDN 有几篇关于 webbrowser 控件的好文章 - WebBrowser Class 有很多例子,How to: Add WebWindows 窗体应用程序的浏览器功能

MSDN has a couple of good articles about the webbrowser control - WebBrowser Class has lots of examples, and How to: Add Web Browser Capabilities to a Windows Forms Application

这篇关于如何等到 WebBrowser 在 VB.NET 中完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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