Webbrowser类DocumentComplete事件未在类中触发(不在WinForm中)

时间:2012-12-24 13:53:19

标签: vb.net class webbrowser-control

我在课堂上使用WebBrowser课程。 我想添加webbrowser_documentcomplete事件处理程序,但我发现事件没有触发。请找到我正在使用的以下代码。此代码使用Windows窗体但不在类中。

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

1 个答案:

答案 0 :(得分:1)

您的DocumentCompleted事件的签名是:

    (ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)

对于编译器并没有对此不以为然。