Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27360

Making a "click event" for the webbrowser control - it's not working after refreshes

$
0
0
[Using VB2010 Winforms / targeting .NET 2.0]

Hey guys,

I'm trying to capture a doubleclick event inside the webbrowser control. When I run the program, it automatically navigates to an URL. Then if I doubleclick inside the webbrowser, it fires the doubleclick event perfectly (displays a MessageBox). But if I then "refresh" the browser page, and then try doubleclicking inside the webbrowser control again, the doubleclick event no longer fires.

Steps to replicate...

1) Drag a webbrowser control and a "refresh" button onto Form1.

2) Code for form1:

Code:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://www.google.com")
    End Sub

    Private Sub Refresh_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Refresh_Button.Click
        WebBrowser1.Refresh()
    End Sub

    Public Sub New()
        InitializeComponent()
        AddHandler WebBrowser1.DocumentCompleted, AddressOf webBrowser1_DocumentCompleted
    End Sub

    Private Sub webBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
        WebBrowser1.Document.Body.AttachEventHandler("ondblclick", AddressOf ShowMessage)
    End Sub

    Private Sub ShowMessage()
        MessageBox.Show("double clicked!")
    End Sub

End Class


What am I doing wrong?

Is there a better way to accomplish this?

Thanks!

Viewing all articles
Browse latest Browse all 27360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>