2011-12-28 61 views
0

我有點卡住了,並且在文檔準備就緒時試圖讓事件觸發。你知道我做錯了什麼嗎?如何檢測WebBrowser控件的documentready事件?

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 

回答

1

你需要給你打電話的導航方法之前添加處理程序:

AddHandler WebBrowser1.DocumentCompleted, New _ 
    WebBrowserDocumentCompletedEventHandler(AddressOf WebBrowser1_DocumentComplete) 
WebBrowser1.Navigate("http://test.com")