如何等到 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