這裏是你如何得到它與DocumentCompleted事件工作:
Private Sub navBtnClick(sender As Object, e As EventArgs)
Dim wbrowser = New WebBrowser()
wbrowser.DocumentCompleted += New WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted)
wbrowser.Navigate("http://www.somesite.com/login")
End Sub
Public Sub WebBrowser_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
Dim webBrowser = TryCast(sender, WebBrowser)
webBrowser.DocumentCompleted -= WebBrowser_DocumentCompleted
'MessageBox.Show(webBrowser.Url.ToString())
webBrowser.Document.GetElementById("login").SetAttribute("value", txtUsername.Text)
webBrowser.Document.GetElementById("passwd").SetAttribute("value", txtPassword.Text)
webBrowser.Document.GetElementById("SI").InvokeMember("Click")
End Sub
如果要導航的文檔具有嵌入其他網頁的iframe,則DocumentCompleted事件會多次觸發。如果您只想僅收到一次該事件,只需按照上面顯示的那樣取消訂閱DocumentCompleted處理程序。