Help with: Handles WebBrowser1.DocumentCompleted , Error

vmars316 621 Reputation points
2020-08-24T19:43:12.26+00:00

Hello & Thanks ;

Having prob with this statement :
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

Error code:

GetElementByTag\Form1.vb(7,156): error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(TextBox1.Text)
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")

        For Each CurElement As HtmlElement In PageElements

            TextBox2.Text = TextBox2.Text & CurElement.GetAttribute("src") & Environment.NewLine

        Next
    End Sub
End Class

Thanks for your Help...

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,874 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 83,286 Reputation points
    2020-08-24T20:29:30.48+00:00

    Where did you define WebBrowser1 ?
    You should have :

    WithEvents WebBrowser1 As New WebBrowser
    
    1 person found this answer helpful.
    0 comments No comments