0
我在類中使用WebBrowser
類。 我想添加webbrowser_documentcomplete事件處理程序,但我發現該事件不發射。請找到我正在使用的以下代碼。此代碼使用Windows窗體但不在課堂上。Webbrowser類DocumentComplete事件不在類中觸發(不在WinForm中)
Imports System.Windows.Forms
Imports System.Threading
Public Class GoogleSearch
Dim WithEvents WBBrowser As New Windows.Forms.WebBrowser
Dim TimCount As New System.Timers.Timer()
Sub New(ByVal SearchParameter As String, ByVal ResultPage As Integer)
TimCount.Interval = 2000
TimCount.Enabled = False
AddHandler TimCount.Elapsed, AddressOf TimCount_Tick
WBBrowser.Visible = True
WBBrowser.ScriptErrorsSuppressed = True
AddHandler WBBrowser.DocumentCompleted, AddressOf WBBrowser_DocumentCompleted
WBBrowser.Navigate("http://www.google.com", False)
End Sub
Private Sub TimCount_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Try
TimCount.Enabled = False
'Some code goes here
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WBBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.EventArgs)
Try
If WBBrowser.ReadyState <> Windows.Forms.WebBrowserReadyState.Complete Then
Return
Else
TimCount.Start()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class