WebBrowser in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the WebBrowser control


This control displays the contents of web pages, XML documents, text files, and other documents understood by the browser.

The control can automatically follow links that the user clicks in the document and provides a standard web browser context menu, containing commands such as Back, Forward, Save Background As, and Print.

Using this control, you can easily add Web-based hypertext to your applications.

For example, you could display an HTML help system or tutorial pages within the control.

The control provides several properties and methods for navigating to different documents

  • Url - gets or sets the control's current web address.
  • Navigate - makes the control open a specific URL.
  • GoBack - makes the control move to the URL it previously displayed.
  • GoForward - after a call to GoBack, makes the control move forward to the next URL it displayed.
  • GoHome - makes the control go to the current user's home page.
  • GoSearch - makes the control go to the current user's search page.

    Private Sub WebBrowserControl_Load(sender As Object, e As EventArgs) _
 Handles Me.Load
    End Sub

    Private Sub GoButton_Click(sender As Object, e As EventArgs) _
 Handles GoButton.Click
    End Sub

    Private Sub BackButton_Click(sender As Object, e As EventArgs) _
 Handles BackButton.Click
    End Sub

    Private Sub ForwardButton_Click(sender As Object, e As EventArgs) _
 Handles ForwardButton.Click
    End Sub

    Private Sub RefreshButton_Click(sender As Object, e As EventArgs)  _
 Handles RefreshButton.Click
    End Sub

    Private Sub HomeButton_Click(sender As Object, e As EventArgs)  _
 Handles HomeButton.Click
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As Object, _
 e As WebBrowserDocumentCompletedEventArgs) _
            Handles WebBrowser1.DocumentCompleted
        Me.Text = WebBrowser1.DocumentTitle
        StatusLabel.Text = "Ready"
    End Sub

    Private Sub WebBrowser1_Navigating(sender As Object, _
 e As WebBrowserNavigatingEventArgs) _
 Handles WebBrowser1.Navigating
        StatusLabel.Text = "Loading..."
    End Sub


Whenever the control moves to a new document, it fires three events.

The Navigating event fires before the control moves to the new document.

The Navigated event occurs after the control has navigated to the new document and is loading it.

The DocumentCompleted event occurs when the control has finished loading the new document.

The control also supports a variety of other events that tell a program when something has changed.

Some of the more useful of these notification events include CanGoBackChanged, CanGoForwardChanged, DocumentTitleChanged, NewWindow (the browser is about to open a new window), ProgressChanged (gives progress information on the download of a document), and StatusTextChanged.

Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2018 - All Rights Reserved.