Extending the AxWebBrowser's Events [ code sample ]

dynamic_sysop

Well-known member
Joined
Oct 1, 2002
Messages
1,039
Location
Ashby, Leicestershire.
Not sure if this will be classed as Ok for the Code section , but here ya go .
Ive noticed on a few boards that people have been asking about the " BeforeNavigate2 " event not triggering when using the AxWebBrowser control , so i decided to tackle the problem and heres the result :
Code:
    Private WithEvents doc As SHDocVw.DWebBrowserEvents_Event
    /// doc will handle all the events for brWeb now...
    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) ///set doc as the active handler for brWebs events.
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        brWeb.Navigate("http://google.com") ///lets navigate to a website.
    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) /// check that before navigate now works.
    End Sub

    Private Sub doc_StatusTextChange(ByVal [Text] As String) Handles doc.StatusTextChange
        Label1.Text = Text ///show the status text in a label.
    End Sub

    Private Sub doc_TitleChange(ByVal [Text] As String) Handles doc.TitleChange
        MyBase.Text = Text /// set the forms caption to the current url
    End Sub

it may help a few people atleast :)
 

Attachments

Last edited by a moderator:
Back
Top