Solved

Create a DocumentCompleted Event Handeler on a WebBrowser control in a moule

Posted on 2011-03-01
2
402 Views
Last Modified: 2012-05-11
I have created a WebBrowser control in a module and got it to navigate to a URL passing certain arguments using the attatched code.

How do i create a Document Complete Event Handeler for this WebBrowser so that I can run more code after the webpage has loaded?
Dim WebBrowser1 As New System.Windows.Forms.WebBrowser
WebBrowser1.Navigate("https://exweb.exchange.uk.com/services/quote.aspx", "", bytePostData1, strHeaders)

Open in new window

0
Comment
Question by:ict-torquilclark
2 Comments
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35007881
Here it is:

 
Public Class Form1

    Dim WebBrowser1 As New System.Windows.Forms.WebBrowser


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf test)

        If True Then
            WebBrowser1.Navigate("https://exweb.exchange.uk.com/services/quote.aspx")
        Else
            WebBrowser1.Navigate("https://ifapreview.exchange.uk.com/services/quote.aspx")
        End If

    End Sub

    Private Sub test(ByVal sender As Object, _
        ByVal e As WebBrowserDocumentCompletedEventArgs)

        Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)

        ' Print the document now that it is fully loaded.
        webBrowserForPrinting.Print()
        MessageBox.Show("print")

        ' Dispose the WebBrowser now that the task is complete. 
        webBrowserForPrinting.Dispose()

    End Sub

End Class

Open in new window


Asim
0
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 35007916
Control events can be found here:
http://msdn.microsoft.com/en-us/library/aa752043%28v=vs.85%29.aspx

Add something like the attached methods, and be sure to call the methods to add and remove handlers.

Also add a method:

Private Sub WebBrowser2_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)

It would be easier, to use a form, than a module, and just drop the webbrowser control, find its event list in the dropdown above and select DocumentCompleted event

Sub AddHandlers()
        AddHandler WebBrowser2.DocumentCompleted(Nothing, Nothing), AddressOf DocumentCompleted
    End Sub

    Sub RemoveHandlers()
        RemoveHandler WebBrowser2.DocumentCompleted, AddressOf DocumentCompleted
    End Sub

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now