Solved

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

Posted on 2011-03-01
2
406 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net/WinForms: adjust Screen Resolution 6 58
fso.FolderExists("\\server\HiddenFolder$") 4 64
C# Single Form 8 42
VB.Net - Project Software to help the Developer 7 33
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

8 Experts available now in Live!

Get 1:1 Help Now