WebBrowser Progress Bar - Visual Basic .NET

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

This tutorial will show you how to make a Progress Bar with a web browser; this tutorial will continue the webbrowser tutorial

Drag a Progress Bar from the toolbox and add it to the form:

The progress bar will show the show the user how much of the requested page has navigated.

Change the Anchor property of the progressbar to Bottom, Left. To do that, right click on the progress bar and go to properties. in the properties window, scroll down to Anchor, and change to Bottom, Left

Right click on the web browser and click on properties. Click on the lightning icon in the properties window:

 Scroll down to Navigating. Double click on the empty textbox next to navigating.

Add the code inside the navigating event

Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
        ProgressBar1.Visible = True
        With ProgressBar1
            .Minimum = 0
            .Maximum = 50
            .Step = 5
        End With
        For index As Integer = 0 To 50 Step 5
            ProgressBar1.Value = index
            System.Threading.Thread.Sleep(35)
        Next
    End Sub

After the webbrowser completes navigating, we should add a code to hide the progress bar:

Right click on the web browser again and go to properties. In the events window, scroll down to DocumnetCompleted. Double click on the empty text box next to it. Add the code inside the Document Completed Event

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles     WebBrowser1.DocumentCompleted
    ProgressBar1.Visible = False
End Sub

Test the program


Share This

Home | About | Contact | Privacy Policy

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