sutcolstudent
New member
- Joined
- Mar 30, 2009
- Messages
- 2
- Programming Experience
- Beginner
Hi. I am a student and I am currently half way through my project, which entails creating a web browser. However I am stuck on the history part. What the question is asking for is a timestamped history, with the use of objects and arrays. I am stuck on what code to use, and how to implement it. I would appreciate any help. The following code is what is included in my project so far:
Thanks for your help .
Paul
VB.NET:
Public Class form1
Private wbBrowserTab(0) As WebBrowser
Private currentTab As Integer
Private Const BLOCK_DEFAULT As String = "[DEFAULT]"
Private Const BLOCK_INTERNETSHORTCUT As String = "[InternetShortcut]"
Private Const ITEM_URL As String = "URL="
Private Const ITEM_BASEURL As String = "BASEURL="
Private Sub Navigate(ByRef URL As String)
If String.IsNullOrEmpty(URL) Then Return
If URL.Equals("about:blank") Then Return
If Not URL.StartsWith("http://") And _
Not URL.StartsWith("https://") Then
URL = "http://" & URL
End If
Try
wbBrowserTab(currentTab).Navigate(URL)
Catch ex As Exception
' Do nothing on Exception
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wbBrowserTab(0) = New WebBrowser
TabControl1.TabPages(0).Controls.Add(wbBrowserTab(0))
wbBrowserTab(0).Dock = DockStyle.Fill
Me.Text = "Web Browser"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TabControl1.TabPages.Add("New tab page")
TabControl1.SelectedIndex() = TabControl1.TabCount - 1
currentTab = TabControl1.SelectedIndex
While currentTab >= wbBrowserTab.Length
ReDim Preserve wbBrowserTab(wbBrowserTab.Length)
End While
wbBrowserTab(currentTab) = New WebBrowser
wbBrowserTab(currentTab).Dock = DockStyle.Fill
TabControl1.TabPages(currentTab).Controls.Add(WebBrowser1)
End Sub
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
WebBrowser1.Navigate(txtURL.Text)
End Sub
Private Sub btnforward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnforward.Click
On Error Resume Next
WebBrowser1.GoForward()
End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
On Error Resume Next
WebBrowser1.GoBack()
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
WebBrowser1.Refresh()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
WebBrowser1.Stop()
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim Open As New OpenFileDialog()
Dim URLFile As String()
Dim myStreamReader As System.IO.StreamReader
Open.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*"
Open.CheckFileExists = True
Open.ShowDialog(Me)
Try
Open.OpenFile()
myStreamReader = System.IO.File.OpenText(Open.FileName)
URLFile = myStreamReader.ReadToEnd().Split(New String() {ControlChars.CrLf}, _
StringSplitOptions.RemoveEmptyEntries)
For Each Item As String In URLFile
If Item.StartsWith(ITEM_URL) Then
Navigate(Item.Substring(ITEM_URL.Length))
Exit For
End If
Next
Catch ex As Exception
' Do nothing on Exception
End Try
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim Save As New SaveFileDialog()
Dim myStreamWriter As System.IO.StreamWriter
Save.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*"
Save.CheckPathExists = True
Save.FileName = wbBrowserTab(currentTab).DocumentTitle
Save.ShowDialog(Me)
Try
myStreamWriter = System.IO.File.CreateText(Save.FileName)
myStreamWriter.Write(BLOCK_DEFAULT & vbCrLf & _
ITEM_BASEURL & wbBrowserTab(currentTab).Url.ToString & vbCrLf & _
BLOCK_INTERNETSHORTCUT & vbCrLf & _
ITEM_URL & wbBrowserTab(currentTab).Url.ToString)
myStreamWriter.Flush()
Catch ex As Exception
' Do nothing on Exception
End Try
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim Response As MsgBoxResult
Response = MsgBox("Are you sure you want to Exit Web Browser?", _
MsgBoxStyle.Question + MsgBoxStyle.YesNo, _
"Web Browser")
If Response = MsgBoxResult.Yes Then
End
End If
End Sub
Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
txtURL.Cut()
End Sub
Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
txtURL.copy()
End Sub
Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
txtURL.paste()
End Sub
Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
txtURL.selectall()
End Sub
Private Sub GoToToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoToToolStripMenuItem.Click
Navigate(txtURL.Text)
End Sub
Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click
WebBrowser1.GoHome()
End Sub
Private Sub txtURL_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtURL.KeyDown
If (e.KeyCode = Keys.Enter) Then
Navigate(txtURL.Text)
End If
End Sub
Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
Me.Text = "Web Browser - " & WebBrowser1.DocumentTitle
txtURL.Text = WebBrowser1.Url.ToString
status.Text = e.Url.ToString()
Me.Text = WebBrowser1.DocumentTitle & " - Web Browser"
ProgressBar1.Visible = True
End Sub
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
ProgressBar1.Value = CInt(e.CurrentProgress)
End Sub
End Class
Thanks for your help .
Paul
Last edited by a moderator: