Now I saw the other thread posting how to make a simple web browser, but I felt like it needed more. So I'm going to show you how make a more advanced web browser, with more functions such as A back, forward, home, refresh button etc. This is done in Visual Basic 2008.
Sorry for the blue text being hard to read, all of this text is in the solution, which is easier to see, and can be compiled.
This is the whole solution, all the code, please don't edit and say you made this.
RapidShare: 1-Click Webhosting
Virus scan:
Antivirus Version Last Update Result
AhnLab-V3 2008.3.22.1 2008.03.21 -
AntiVir 7.6.0.75 2008.03.22 -
Authentium 4.93.8 2008.03.22 -
Avast 4.7.1098.0 2008.03.23 -
AVG 7.5.0.516 2008.03.22 -
BitDefender 7.2 2008.03.23 -
CAT-QuickHeal 9.50 2008.03.21 -
ClamAV 0.92.1 2008.03.23 -
DrWeb 4.44.0.09170 2008.03.23 -
eSafe 7.0.15.0 2008.03.18 -
eTrust-Vet 31.3.5633 2008.03.21 -
Ewido 4.0 2008.03.23 -
F-Prot 4.4.2.54 2008.03.22 -
F-Secure 6.70.13260.0 2008.03.21 -
FileAdvisor 1 2008.03.23 -
Fortinet 3.14.0.0 2008.03.23 -
Ikarus T3.1.1.20 2008.03.23 -
Kaspersky 7.0.0.125 2008.03.23 -
McAfee 5257 2008.03.21 -
Microsoft 1.3301 2008.03.23 -
NOD32v2 2967 2008.03.21 -
Norman 5.80.02 2008.03.20 -
Panda 9.0.0.4 2008.03.23 -
Prevx1 V2 2008.03.23 -
Rising 20.36.62.00 2008.03.23 -
Sophos 4.27.0 2008.03.23 -
Sunbelt 3.0.978.0 2008.03.18 -
Symantec 10 2008.03.23 -
TheHacker 6.2.92.252 2008.03.22 -
VBA32 3.12.6.3 2008.03.21 -
VirusBuster 4.3.26:9 2008.03.22 -
Webwasher-Gateway 6.6.2 2008.03.23 -
Ok here is what each thing does:
THIS IS FOR THE MAIN FORM - FORM1
Public Class Form1
'This tells the webbrowser to navigate to whatever link you put in the search box
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
'This refreshes the page in the webbrowser if pressed
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
WebBrowser1.Refresh()
End Sub
'These are the functions that happen when the form loads
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Declares this form as form1 in the form library
myFormLibrary.Form1 = Me
'This navigates to google on start up
WebBrowser1.Navigate("Google.com")
'this clears the textbox on start up
ToolStripStatusLabel1.Text = ""
'this starts the timer that fills the status label
Timer1.Start()
End Sub
'This tells the webbrowser to go back one page if pressed
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
WebBrowser1.GoBack()
End Sub
'Tells the webbrowser to go to the next page if pressed
Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
WebBrowser1.GoForward()
End Sub
'Shows the About me form if pressed
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
Dim formabout As New FormAbout
formabout.Show()
End Sub
'Closes the program if the exit button in the menu is clicked
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
'This is used to show the status text or the current link that your mouse is over in the toolstrip label
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'this resets the progress bar if the Status Text is "Done" every timer tick
If ToolStripStatusLabel1.Text = "Done" Then
ToolStripProgressBar1.Value = 0
End If
'This shows the status text or the link your mouse is over every timer tick
ToolStripStatusLabel1.Text = WebBrowser1.StatusText
End Sub
'This takes the information from the textbox and searches it on google and displays it in the webbrowser
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://www.google.com/search?hl=en&q=" + TextBox2.Text + "&btnG=Google+Search&aq=f")
End Sub
'Places the name of the current website in the url
Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
'Changes the tab text to the host of the website
TabPage1.Text = WebBrowser1.Url.Host
'Changes the textbox to the current link
TextBox1.Text = WebBrowser1.Url.ToString
End Sub
'This will show a dialog to where you can save the page for offline use.
Private Sub SavePageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SavePageToolStripMenuItem.Click
WebBrowser1.ShowSaveAsDialog()
End Sub
'This will make the progress work
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
ToolStripProgressBar1.PerformStep()
If ToolStripProgressBar1.Maximum = ToolStripProgressBar1.Value Then
ToolStripProgressBar1.Value = 0
End If
End Sub
'Important notes about the design -
'For the toolstripstatuslabel, set the spring property to true, and then set the text alignment to mid left
'For the tabcontrol1 set the anchors to all directions, this will cause it to stretch if the window is maximized
'The google search bar label, the text box after that and the button after that all have their anchors set to the top right,
'this will cause them to go to that part of the screen when maximized
'The screen is set to auto maximize on load
End Class
End of Main Form - Form1
This is for the Bookmarks form - frmBookmarks
'Imports to the form
Imports System.IO
Public Class frmBookmarks
'closes form on close button click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
'shows list on form load
Private Sub frmBookmarks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Declares this form as frmBookmarks in the myFormLibrary Class
myFormLibrary.frmBookmarks = Me
'Clears the listbox
Me.ListBox1.Items.Clear()
'Dims the file as a string
Dim file As String
'gets all the files in the directory
Dim files() As String = Directory.GetFiles("C:\Program Files\Web Browser Demo\Bookmarks\")
'for loop that adds the file location to the listbox as an item
For Each file In files
'adds to the listbox
Me.ListBox1.Items.Add(file)
Next
'Sorts the listbox
Me.ListBox1.Sorted = True
'Allows the listbox to be scrollable
ListBox1.ScrollAlwaysVisible = True
'Starts the refresh timer
Timer1.Start()
End Sub
'updates the list every timer tick
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'clears the list box so there is no file repetition when the names are placed in the listbox
Me.ListBox1.Items.Clear()
'Dims the file as a string
Dim file As String
'gets all the files in the directory
Dim files() As String = Directory.GetFiles("C:\Program Files\Web Browser Demo\Bookmarks\")
'for loop that adds the file location to the listbox as an item
For Each file In files
'adds to the listbox
Me.ListBox1.Items.Add(file)
Next
'Sorts the listbox
Me.ListBox1.Sorted = True
'Allows the listbox to be scrollable
ListBox1.ScrollAlwaysVisible = True
End Sub
'Stops timer if an item in the list is clicked
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Timer1.Stop()
End Sub
'opens the file in the bookmarks tab of the main form
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Dims the file name as a string
Dim FileName As String
'The file name is the selected listbox item
FileName = ListBox1.SelectedItem
'dims a new filestream to open the selected file
Dim fs As FileStream = File.OpenRead(FileName)
'dims a new reader to read the file
Dim sr As New StreamReader(fs)
'Reads all the text
Dim text As String = sr.ReadToEnd()
'Navigates to the bookmark in the webbrowser
Form1.WebBrowser1.Navigate(text)
'closes the bookmark form
Me.Close()
End Sub
'starts timer again if the form loses focus
Private Sub frmBookmarks_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
Timer1.Start()
End Sub
'Deletes the bookmark file if selected
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Dims the a string for a variable
Dim FileToDelete As String
'the file to be deleted is the selected listbox item
FileToDelete = ListBox1.SelectedItem
'if the file exists, then the file is deleted and a message box is show and then the item is removed from the list box
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
MsgBox("File Deleted")
ListBox1.Items.Remove(ListBox1.SelectedItem)
End If
End Sub
'Closes the form if button is pressed
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
'Important notes about the bookmarks, this program must be placed on the C drive for this to work correctly,
'this program must also have sufficient privileges so that it can create the bookmarks directory.
End Class
End of Bookmarks Form - frmBookmarks
That is all the code explained. If you need more assistance please let me know.