Click here to Skip to main content
Licence 
First Posted 14 Jul 2003
Views 102,153
Bookmarked 16 times

Extending the axWebbrowser control events.

By | 14 Jul 2003 | Article
How to extend the axWebbrowser's events in VB.NET.

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 
     '/// 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 brweb's 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 form's caption to the current url 
     End Sub

License

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

About the Author

dynamic



United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow can I record all http activity of shdocvw PinmemberSuber1:50 4 Mar '08  
Questionhow 2 work with combo box using axWebBrowser1 ? Pinmembervedmack22:52 7 Jan '06  
AnswerRe: how 2 work with combo box using axWebBrowser1 ? PinmemberDatta Deshmukh20:33 23 Nov '08  
GeneralAxWebBrowser Proxy Set PinmemberUsman Syed18:22 14 Dec '05  
GeneralAutoLogin in Forums PinmemberVitoto15:27 5 Oct '05  
GeneralAxWeb browser PinsussLalit Dubey1:54 26 Jun '05  
GeneralDebugging axWebbrowser control events PinmemberTysonM20:39 7 Feb '04  
QuestionHai it's working fine... How do i handle javascript errors? PinmemberAjai Kumar Ramamoorthy1:46 20 Dec '03  
General[Q] web session lost..on pop-up window. Pinmemberjucy0:20 18 Sep '03  
GeneralRe: [Q] web session lost..on pop-up window. PinsussAnonymous18:32 19 Jun '04  
GeneralRe: [Q] web session lost..on pop-up window. Pinmemberlorenzo.gardoni21:38 7 May '07  
Generaljust the job Pinsussdave stewart5:10 16 Jul '03  
GeneralRe: just the job Pinmemberdynamic22:19 20 Jul '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 15 Jul 2003
Article Copyright 2003 by dynamic
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid