MikeCorruption
New member
- Joined
- Jan 28, 2014
- Messages
- 1
- Programming Experience
- Beginner
Hey guys, ive been given a project of a web browser to complete and ive built the whole web browser but there are two parts i just cannot seem to get working, i have tried many youtube guides and nothing, i am getting the same issues.
First here is the whole of my Web Browser code:
That part of the code is meant to allow the "History" to load after the browser is closed and reopened and it doesnt, one last problem, i cant seem to get any time stamps next to it.
Sorry if that is a lot, it is just really frustrating that i cant seem to get three elements working, any help even for one element would help me greatly
First here is the whole of my Web Browser code:
VB.NET:
Imports System.IOPublic Class Form1
'Declaring i to be used as an integer
Dim int As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Declaring Browse, when Form loads this code will load a Web Browser inside a new tab.
Dim Browser As New WebBrowser
TabControl1.TabPages.Add("New Tab")
TabControl1.SelectTab(1 - 1)
Browser.Name = "webbrowser"
Browser.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser)
AddHandler Browser.DocumentCompleted, AddressOf Done
int = int + 1
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.HomePage)
recoverhistory()
For Each item In My.Settings.Bookmark
tsbURL.Items.Add(item)
Next
End Sub
Private Sub TogglePanelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TogglePanelToolStripMenuItem.Click
'This code toggles the panel on/off
togglePane()
End Sub
Sub togglePane()
'Optional Code for a Button to show and hide panel
' bIndex = (bIndex + 1) Mod 2
'btnShow.Text = status(bIndex)
' This collapses the Panel where the tabs for History, Favourites etc are kept.
SplitContainer1.Panel1Collapsed = Not SplitContainer1.Panel1Collapsed
End Sub
Private Sub tsbAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbAdd.Click
'This code means that a new tab will be added called "New Tab"
Dim Browser As New WebBrowser
TabControl1.TabPages.Add("New Tab" & int)
TabControl1.SelectTab(int)
Browser.Name = "webbrowser"
Browser.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser)
int = int + 1
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.HomePage)
AddHandler Browser.DocumentCompleted, AddressOf Done
End Sub
Private Sub tsbRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbRemove.Click
'This IF statement will check if the there is more than 1 tab open, if yes then the code removes most recent tab from the tab control.
If int > 1 Then
TabControl1.TabPages.Remove(TabControl1.SelectedTab)
TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
int = int - 1
End If
End Sub
Private Sub tsbBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbBack.Click
'This code will take the web browser back one page in the current opened tab.
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
End Sub
Private Sub tsbForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbForward.Click
'This code will take the web browser forward one page in the current opened tab.
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
End Sub
Private Sub tsbStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbStop.Click
'This code will stop the selected tab from loading the page any further
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Stop()
End Sub
Private Sub tsbRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbRefresh.Click
'This code will refresh the current tab
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Refresh()
End Sub
Private Sub tsbSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbSearch.Click, tsbURL.Enter
'This code will go to the URL typed into the the URL combo box and will display the page in the selected tab.
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(tsbURL.Text)
saveToHistory()
End Sub
Private Sub Done(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
'This code changes the Tab name from "New Tab" to the Website name that is currently displayed
TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
tsbURL.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
End Sub
Sub saveToHistory()
'Adds any Information typed into URL box into the History
If (Not tsbURL.Text = "") Then
lbHistory.Items.Add(tsbURL.Text)
tsbURL.Items.Add(tsbURL.Text)
If (Not lbHistoryUnique.Items.Contains(tsbURL.Text)) Then
lbHistoryUnique.Items.Add(tsbURL.Text)
End If
End If
mostPopular()
End Sub
Sub mostPopular()
'This code organises the History of Webpages accessed into the most viewed
Dim i As Integer
Dim j As Integer
Dim tmpCount As Integer
lbHistoryUnique.Sorted = True
lbCount.Sorted = True
lbCount.Items.Clear()
For i = 0 To lbHistoryUnique.Items.Count - 1
tmpCount = 0
For j = 0 To lbHistory.Items.Count - 1
If lbHistoryUnique.Items(i) = lbHistory.Items(j) Then
tmpCount += 1
End If
Next
lbCount.Items.Add(tmpCount & ":" & (lbHistoryUnique.Items(i)))
Next
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'This code removes all entries in the History section.
lbCount.Items.Clear()
lbHistory.Items.Clear()
lbHistoryUnique.Items.Clear()
End Sub
Private Sub btnReverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReverse.Click
'In the History, this code reverses the items listed in alphabetical order
Dim i As Integer
Dim tmpCount As Integer
lbCount.Sorted = False
tmpCount = lbCount.Items.Count - 1
For i = tmpCount To 0 Step -1
lbCount.Items.Add(lbCount.Items(i))
Next
For i = 0 To tmpCount
lbCount.Items.RemoveAt(0)
Next
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
'When this button is pressed the current URL in the URL box will be now the Home Page.
My.Settings.HomePage = tsbURL.Text
End Sub
Private Sub savehistory()
'This code saves the history in a text format on the C Drive.
Using w As StreamWriter = New StreamWriter("C:\mike")
Dim i As Integer
For i = 0 To lbHistory.Items.Count - 1
w.WriteLine(lbHistory.Items.Item(i))
Next
End Using
End Sub
Private Sub recoverhistory()
'This code reloads the history that is storedo n the C drive
Dim myHistory() As String
Using r As StreamReader = New StreamReader("C:\\mike.txt")
myHistory = r.ReadToEnd.Split(vbNewLine)
End Using
Dim i As Integer
For i = 0 To myHistory.Length - 1
lbHistory.Items.Add(myHistory(i))
Next
End Sub
'Add a Bookmark to the Bookmarks page
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
My.Settings.Bookmark.Add(tsbURL.ToString)
tsbURL.Items.Add(tsbURL.ToString)
bookmarks.ListBox1.Items.Add(tsbURL.ToString)
End Sub
'Opens the Bookmarks Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bookmarks.Visible = True
End Sub
End Class
VB.NET:
Private Sub savehistory() 'This code saves the history in a text format on the C Drive.
Using w As StreamWriter = New StreamWriter("C:\mike")
Dim i As Integer
For i = 0 To lbHistory.Items.Count - 1
w.WriteLine(lbHistory.Items.Item(i))
Next
End Using
End Sub
Private Sub recoverhistory()
'This code reloads the history that is storedo n the C drive
Dim myHistory() As String
Using r As StreamReader = New StreamReader("C:\\mike.txt")
myHistory = r.ReadToEnd.Split(vbNewLine)
End Using
Dim i As Integer
For i = 0 To myHistory.Length - 1
lbHistory.Items.Add(myHistory(i))
Next
End Sub
That part of the code is meant to allow the "History" to load after the browser is closed and reopened and it doesnt, one last problem, i cant seem to get any time stamps next to it.
Sorry if that is a lot, it is just really frustrating that i cant seem to get three elements working, any help even for one element would help me greatly
Last edited: