VB Tutor VB.NET 2022 Tutorial VB2019 Tutorial VB6 Tutorial VB Sample Code About Us
Visual Basic Sample Code

Web Browser

Create a custom web browser with Visual Basic 6 and VB.NET


Creating a web browser in Visual Basic is an excellent way to learn about COM components and web integration. In VB6, you use the Microsoft Internet Control component, while in VB.NET you can use the built-in WebBrowser control.

This sample demonstrates how to create a fully functional web browser with navigation controls, URL bar, and status indicators. Explore the code examples below to see how it's done in both VB6 and VB.NET.

Interactive Browser Demo

Try our simulated web browser below. This demo mimics the functionality of a VB-based browser using JavaScript.

Status: Ready

Code Examples

Visual Basic 6 Web Browser

To create a web browser in VB6, you need to add the Microsoft Internet Control component. This control appears as a small globe in your toolbox.

Private Sub Form_Load()
    ' Navigate to default page on startup
    WebBrowser1.Navigate "https://www.vbtutor.net"
End Sub

Private Sub btnGo_Click()
    ' Navigate to URL entered in combo box
    WebBrowser1.Navigate Combo1.Text
End Sub

Private Sub btnBack_Click()
    ' Go to previous page
    WebBrowser1.GoBack
End Sub

Private Sub btnForward_Click()
    ' Go to next page
    WebBrowser1.GoForward
End Sub

Private Sub btnRefresh_Click()
    ' Refresh current page
    WebBrowser1.Refresh
End Sub

Private Sub btnHome_Click()
    ' Navigate to home page
    WebBrowser1.Navigate "https://www.vbtutor.net"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    ' Update combo box with current URL
    Combo1.Text = URL
    ' Update form caption with page title
    Form1.Caption = WebBrowser1.LocationName
    ' Add URL to history
    Combo1.AddItem URL
End Sub

Private Sub WebBrowser1_DownloadBegin()
    ' Show loading status
    Combo1.Text = "Page loading, please wait..."
End Sub

VB.NET Web Browser

In VB.NET, the WebBrowser control is part of the standard toolbox. The implementation is similar to VB6 but with .NET syntax.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' Navigate to default page on startup
    WebBrowser1.Navigate("https://www.vbtutor.net")
End Sub

Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
    ' Navigate to URL entered in combo box
    WebBrowser1.Navigate(ComboBox1.Text)
End Sub

Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
    ' Go to previous page
    WebBrowser1.GoBack()
End Sub

Private Sub btnForward_Click(sender As Object, e As EventArgs) Handles btnForward.Click
    ' Go to next page
    WebBrowser1.GoForward()
End Sub

Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
    ' Refresh current page
    WebBrowser1.Refresh()
End Sub

Private Sub btnHome_Click(sender As Object, e As EventArgs) Handles btnHome.Click
    ' Navigate to home page
    WebBrowser1.Navigate("https://www.vbtutor.net")
End Sub

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    ' Update combo box with current URL
    ComboBox1.Text = WebBrowser1.Url.ToString()
    ' Update form caption with page title
    Me.Text = WebBrowser1.Document.Title
    ' Add URL to history
    ComboBox1.Items.Add(WebBrowser1.Url.ToString())
End Sub

Private Sub WebBrowser1_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
    ' Show loading status
    lblStatus.Text = "Loading: " & e.Url.ToString()
End Sub

Implementation Guide

Adding the Control

VB6: Press Ctrl+T, select "Microsoft Internet Control"

VB.NET: The WebBrowser control is in the toolbox under "Common Controls"

Interface Design

Create navigation buttons (Back, Forward, Refresh, Home), a URL input (ComboBox), and a large area for the WebBrowser control

Key Methods

Navigate(url) - Load a web page

GoBack(), GoForward() - Navigation history

Refresh() - Reload current page

Important Events

DocumentComplete - Page finished loading

Navigating - Page starting to load

StatusTextChange - Status bar updates

Pro Tip: Enhancing Your Browser

Consider adding these features to make your browser more robust:

  • Tabbed browsing interface
  • Bookmarks management system
  • Download manager
  • Privacy mode (incognito)
  • Popup blocker