Click here to Skip to main content
15,885,101 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am using WebBrowser class in class.
I am trying to add webbrowser_documentcomplete event handler but I found that event not firing.
Please find below code I am using. This code working with an Windows Form but not in class.
VB
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

Thanks in advance.

[Edit]Code block added[/Edit]
Posted
Updated 24-Dec-12 3:35am
v2

1 solution

It's not going to work. The WebBrowser control NEEDS to be on a Form in order to work properly.

Since this is a class library, you're probably using a web browser control to do something better suited to the HttpRequest classes and methods. What are you doing with this?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900