'This is a code to trap the link clicking event hope it will help to get the button clicking event.
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim olink As HtmlElement
Dim olinks As HtmlElementCollection = WebBrowser1.Document.Links
For Each olink In olinks
olink.AttachEventHandler("onclick", AddressOf LinkClicked)
Next
End Sub
Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs)
Dim link As HtmlElement = WebBrowser1.Document.ActiveElement
Dim url As String = link.GetAttribute("href")
MsgBox("Link Clicked: " & link.InnerText & vbCrLf & _
"Destination: " & url)
End Sub
Imports System.Runtime
Imports System.ComponentModel
'Extend the WebBrowser control
Public Class ExtendedWebBrowser
Inherits WebBrowser
Private cookie As AxHost.ConnectionPointCookie
Private events As WebBrowserExtendedEvents
'This method will be called to give you a chance to create your own event sink
Protected Overloads Overrides Sub CreateSink()
'MAKE SURE TO CALL THE BASE or the normal events won't fire
MyBase.CreateSink()
events = New WebBrowserExtendedEvents(Me)
cookie = New AxHost.ConnectionPointCookie(Me.ActiveXInstance, events, GetType(DWebBrowserEvents2))
End Sub
Protected Overloads Overrides Sub DetachSink()
If cookie IsNot Nothing Then
cookie.Disconnect()
cookie = Nothing
End If
MyBase.DetachSink()
End Sub
'This new event will fire when the page is navigating
Public Event NewWindowWithTaget As EventHandler(Of WebBrowserExtendedNavigatingEventArgs)
Protected Sub OnNewWindow3(ByVal url As String, ByVal e As WebBrowserExtendedNavigatingEventArgs)
RaiseEvent NewWindowWithTaget(Me, e)
End Sub
'This class will capture events from the WebBrowser
Private Class WebBrowserExtendedEvents
Inherits System.Runtime.InteropServices.StandardOleMarshalObject
Implements DWebBrowserEvents2
Private _Browser As ExtendedWebBrowser
Public Sub New(ByVal browser As ExtendedWebBrowser)
_Browser = browser
End Sub
Public Sub NewWindow3(ByVal pDisp As Object, ByRef cancel As Boolean, ByRef flags As Object, ByRef hostURL As Object, ByRef URL As Object) Implements DWebBrowserEvents2.NewWindow3
Dim args As New WebBrowserExtendedNavigatingEventArgs(URL)
args.Cancel = cancel
_Browser.OnNewWindow3(URL, args)
cancel = args.Cancel
End Sub
End Class
<InteropServices.ComImport(), InteropServices.Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D"), InteropServices.InterfaceTypeAttribute(InteropServices.ComInterfaceType.InterfaceIsIDispatch), InteropServices.TypeLibType(InteropServices.TypeLibTypeFlags.FHidden)> _
Public Interface DWebBrowserEvents2
<InteropServices.DispId(273)> _
Sub NewWindow3(ByVal pDisp As Object, ByRef cancel As Boolean, ByRef flags As Object, ByRef hostURL As Object, ByRef URL As Object)
End Interface
End Class
Public Class WebBrowserExtendedNavigatingEventArgs
Inherits CancelEventArgs
Private _Url As String
Public Sub New(ByVal url As String)
_Url = url
End Sub
Public ReadOnly Property Url() As String
Get
Return _Url
End Get
End Property
End Class