我有点卡住并试图在文档准备好时触发事件。你知道我做错了吗?
Public Class Form1
'Declaration
Public Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler
Private Sub Main(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Dim frm As New Form1
'frm.Show()
WebBrowser1.Navigate("http://test.com")
AddHandler WebBrowser1.DocumentCompleted, New _
WebBrowserDocumentCompletedEventHandler(AddressOf WebBrowser1_DocumentComplete)
Me.Text = WebBrowser1.ReadyState
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles Me.DocumentCompleted
Me.Text = WebBrowser1.ReadyState
End Sub
End Class
答案 0 :(得分:1)
您需要在调用导航方法之前添加处理程序:
AddHandler WebBrowser1.DocumentCompleted, New _
WebBrowserDocumentCompletedEventHandler(AddressOf WebBrowser1_DocumentComplete)
WebBrowser1.Navigate("http://test.com")