Jump to content
zbeng

VisualBasic2005

Recommended Posts

Please be paitient the GIF has 11images and each image updates about once every 5secs.

Click on the thumbnail to view a full size image.

ThumbNail:simplewebtutorialpy6.th.gif

Once you have viewed the GIF and added all the controls to your application, add the code below to make it work. We are not renaming any of the components, so the code will work with ur project as well.

Public Class Tut_Wb

'---------------------------------------------------------------------------------
'When you click on the 'BAck' button, go back, if the Browser can go back.
'---------------------------------------------------------------------------------

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
If WebBrowser1.CanGoBack Then
WebBrowser1.GoBack()
Else
Return
End If
End Sub

'---------------------------------------------------------------------------------
'When you click on the 'Forward' button, go forward, if the Browser can go forward
'---------------------------------------------------------------------------------
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
If WebBrowser1.CanGoForward Then
WebBrowser1.GoForward()
Else
Return
End If
End Sub

'--------------------------------------------------------------------------
'When u click on the 'Go' button, start browsing to address in the combobox
'--------------------------------------------------------------------------
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
If ToolStripComboBox1.Text <> "" Then
WebBrowser1.Navigate(ToolStripComboBox1.Text)
Else
WebBrowser1.GoHome()
End If
End Sub

'---------------------------------------------------------------------
'When u click on the close button, Stop browsing
'---------------------------------------------------------------------
Private Sub ToolStripButton4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
WebBrowser1.Stop()
End Sub

'-----------------------------------------------------------------------------------
'When the form is closed dispose of all the resources being used.
'-----------------------------------------------------------------------------------
Private Sub Tut_Wb_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
WebBrowser1.Dispose()
End Sub

'------------------------------------------------------------------------------------
'When u press enter, take the text in the combo box and navigate to
'the address in the combobox.
'------------------------------------------------------------------------------------
Private Sub ToolStripComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ToolStripComboBox1.KeyDown
' When we press enter we want to browse just like the real browser.
If e.KeyCode = (Keys.Enter) Then
Dim stringUrl As String
stringUrl = ToolStripComboBox1.Text
If stringUrl = "" Then
Return
Else
WebBrowser1.Navigate(stringUrl)
End If
End If

End Sub

'---------------------------------------------------------------------------------
'Make the backspace work. When u press the 'backspace' go back to the
'last page visited.
'---------------------------------------------------------------------------------
Private Sub Tut_Wb_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Back Then
If WebBrowser1.CanGoBack Then
WebBrowser1.GoBack()
Else
Return
End If
End If
End Sub

'---------------------------------------------------------------------------------
'As the form loads..we set it's start position to center of the screen and
'Set windowstate to maximized.
'---------------------------------------------------------------------------------
Private Sub Tut_Wb_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'If you have used VB before you know why we use Me. For those who
'are used to JAVA 'ME' is like 'this' refering to the same object.
Me.StartPosition = FormStartPosition.CenterScreen
Me.WindowState = FormWindowState.Maximized

WebBrowser1.GoHome()
End Sub

'------------------------------------------------------------------------
'When navigation to a particular webpage is complete change the caption
'to the title of the web page.
'------------------------------------------------------------------------
Private Sub WebBrowser1_DocumentTitleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.DocumentTitleChanged
Me.Text = WebBrowser1.DocumentTitle & "-My WebBrowser"
End Sub

'---------------------------------------------------------------------------------
'Make the progress bar work, As the progress of the webpage is changed we update the progressbar to represent the current progress
'---------------------------------------------------------------------------------
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged

ToolStripProgressBar1.Visible = True

If e.CurrentProgress <= 0 Then
ToolStripProgressBar1.Value = 0
ToolStripProgressBar1.Visible = False
Else
'This code was borrowed from MSDN, the previous progress bar
'I had, was moving too fast. This one moves in smooth steps.
ToolStripProgressBar1.Value = Math.Min(ToolStripProgressBar1.Maximum, Convert.ToInt32(Math.Floor(ToolStripProgressBar1.Maximum * (e.CurrentProgress / e.MaximumProgress))))
End If

End Sub

End Class

Frankly speaking this project is really easy because of the webbrowser control in the VB2005. It actually makes it easy to create a custom webBrowser. The only thing you need to keep in mind is what you want, how to make the browser cool.

Note: The code here has some errors in it(It still works even with the errors). Can you find them?

Anyone figured out what the errors are?

You will need to understand this application in detail to continue with the next part of it which I will be posting pretty soon. So, try out this tutorial and let me know via PM what your thoughts are.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...