Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-01
2
Medium Priority
?
422 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

782 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