Introduction
I have seen several messages on various VB.NET boards regarding problems with the axWebbrowser control (the BeforeNavigate2 event not working), so I decided to try to combat the issue and here is the result.
Using the code
Firstly, add a axWebbrowser control to a form, in this case called brweb. Then we need to add a SHDocVw.DWebBrowserEvents_Event below the "Windows generated code" area. This will be the new event handler for brWeb. Next, it's a simple test using a few lines of code to show how the BeforeNavigate event is handled.
Private WithEvents doc As SHDocVw.DWebBrowserEvents_Event
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim b As Object = brWeb.Application
doc = DirectCast(b, SHDocVw.WebBrowser_V1)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
brWeb.Navigate("http://google.com") End Sub
Private Sub doc_BeforeNavigate(ByVal URL As String, _
ByVal Flags As Integer, ByVal TargetFrameName As String, _
ByRef PostData As Object, ByVal Headers As String, _
ByRef Cancel As Boolean) Handles doc.BeforeNavigate
MessageBox.Show(URL) End Sub
Private Sub doc_StatusTextChange(ByVal _
[Text] As String) Handles doc.StatusTextChange
Label1.Text = Text End Sub
Private Sub doc_TitleChange(ByVal [Text] As String) _
Handles doc.TitleChange
MyBase.Text = Text End Sub
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here