Today we are going to create a simple web browser with VB.NET. Let’s get started.
UI
The UI for this project requires the following components.
- a toolstrip
- 9 toolstrip buttons
- a tool strip textbox
- a listbox
- a WebBrowser control
Apply these settings to the Form:
Name | frmMain |
Size | 1162, 614 |
Text | Simple WebBrowser |
Then rename the file to frmMain.
Apply these settings to the buttons:
Name | Text |
btnSettings | Settings |
btnHome | Home |
btnBack | Back |
btnForward | Forward |
btnRefresh | Refresh |
btnGo | Go |
btnAdd | Add |
btnDelete | Delete |
btnClear | Clear |
Apply these settings to the TextBox:
Name | txtURL |
Width | 655 |
Apply these settings to the ListBox:
Name | lstBookMarks |
Dock | Right |
Width | 168 |
Apply these settings to the WeBrowser:
Name | wbMain |
Size | 960, 547 |
Anchor | Top, Bottom, Left, Right |
When you’re done it should resemble this:

Then add this code:
Imports System.IO
Public Class frmMain
Private dtweb As DataTable
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btnHome.Click
txtURL.Text = My.Computer.FileSystem.ReadAllText("your path")
wbMain.Navigate(txtURL.Text)
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dtweb = New DataTable()
dtweb.Columns.Add("web", GetType(String))
Using r As StreamReader = New StreamReader("your path)
Dim line As String
line = r.ReadLine
If Not IsNothing(line) Then
If line.Length > 0 Then
Dim dr As DataRow = dtweb.NewRow
dr.Item("web") = line
dtweb.Rows.Add(dr)
End If
End If
Do While (Not line Is Nothing)
Console.WriteLine(line)
line = r.ReadLine
If Not IsNothing(line) Then
If line.Length > 0 Then
Dim dr As DataRow = dtweb.NewRow
dr.Item("web") = line
dtweb.Rows.Add(dr)
End If
End If
Loop
End Using
lstBookMarks.DataSource = dtweb
lstBookMarks.DisplayMember = "web"
txtURL.Text = My.Computer.FileSystem.ReadAllText("your path")
wbMain.Navigate(txtURL.Text)
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim strNewBookMark As String = txtURL.Text
For Each dr As DataRow In dtweb.Rows
If dr(0) = strNewBookMark Then
MessageBox.Show("This bookmark already exists and will Not be added")
Exit Sub
End If
Next
dtweb.Rows.Add(txtURL.Text)
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("your path", False)
For Each dr As DataRow In dtweb.Rows
file.WriteLine(dr(0))
Next
file.Close()
End Sub
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
wbMain.GoBack()
End Sub
Private Sub btnForward_Click(sender As Object, e As EventArgs) Handles btnForward.Click
wbMain.GoForward()
End Sub
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
wbMain.Refresh()
End Sub
Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
wbMain.Navigate(txtURL.Text)
End Sub
Private Sub lstBookMarks_SelectedValueChanged(sender As Object, e As EventArgs) Handles lstBookMarks.SelectedValueChanged
If Not IsNothing(sender.selecteditem) Then
wbMain.Navigate(sender.selecteditem.item(0))
txtURL.Text = sender.selecteditem.item(0)
End If
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
dtweb.Clear()
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
dtweb.Rows.RemoveAt(lstBookMarks.SelectedIndex)
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("your path", False)
For Each dr As DataRow In dtweb.Rows
file.WriteLine(dr(0))
Next
file.Close()
End Sub
End Class
Add a new form called frmSettings. Then add the following components:
- a label
- a button
- a textbox
- a listbox
Apply the following settings to the form:
Text | Settings |
Size | 452, 489 |
Apply the following settings to the components:
Component | Name | Size | Location | Text |
Label | Label1 | N/A | 12, 9 | Home Page: |
Button | btnSave | 75, 23 | 348, 4 | Save |
TextBox | txtHomePage | 261, 20 | 81, 6 | N/A |
ListBox | lstPages | 408, 407 | 15, 32 | N/A |
Next, add this code:
Public Class frmSettings
Private dtweb As DataTable
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("your path", False)
file.WriteLine(txtHomePage.Text)
file.Close()
End Sub
Private Sub frmSettings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtHomePage.Text = My.Computer.FileSystem.ReadAllText("your path")
dtweb = New DataTable()
dtweb.Columns.Add("web", GetType(String))
dtweb.Rows.Add("bing.com")
dtweb.Rows.Add("google.com")
dtweb.Rows.Add("ecosia.com")
dtweb.Rows.Add("duckduckgo.com")
lstPages.DataSource = dtweb
lstPages.DisplayMember = "web"
lstPages.ValueMember = "web"
End Sub
Private Sub lstPages_SelectedValueChanged(sender As Object, e As EventArgs) Handles lstPages.SelectedValueChanged
Try
txtHomePage.Text = lstPages.SelectedValue
Catch ex As Exception
End Try
End Sub
End Class
Add this code to the bottom of the main form:
Private Sub btnSettings_Click(sender As Object, e As EventArgs) Handles btnSettings.Click
frmSettings.ShowDialog()
End Sub
Next, go to the paths you specified and create those files.
Finally hit the start button and enjoy.
Please note that the browser component relies on the Trident rendering engine which is now deprecated.