In this program a browser will be created and we will be able to be
Back, forward, refresh, stop, and go to homepage. The form will
Look as follow.
In code window above the class Form1 write following 4 lines to import
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Windows.Forms
Now double click the back button and write the following code in side button1_Click sub.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.GoBack()
TextBox1.Text = WebBrowser1.Url.ToString()
End Sub
Now double click the Forward button and write the following code in side button2_Click sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.GoForward()
TextBox1.Text = WebBrowser1.Url.ToString()
End Sub
Now double click the Stop button and write the following code in side button3_Click sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
WebBrowser1.Stop()
End Sub
Now double click the Refresh button and write the following code in side button4_Click sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.Refresh()
End Sub
Now double click the home button and write the following code in side button5_Click sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.GoHome()
TextBox1.Text = WebBrowser1.Url.ToString()
End Sub
Now double click the form and write the following code in side from load Click sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
End Sub
Now double click the web browser1 and choose from the Dropdown event to
“CanGoBackChanged”.
Now write the following code in sub
WebBrowser1_CanGoBackChanged
Private Sub WebBrowser1_CanGoBackChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.CanGoBackChanged
If WebBrowser1.CanGoBack = True Then
Button1.Enabled = True
Else
Button1.Enabled = False
End If
End Sub
Now do the same and create Sub WebBrowser1_CanGoForwardChanged
And write the following code inside the sub.
Private Sub WebBrowser1_CanGoForwardChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.CanGoForwardChanged
If WebBrowser1.CanGoForward = True Then
Button2.Enabled = True
Else
Button2.Enabled = False
End If
End Sub
Again do the same for the following sub WebBrowser1_DocumentCompleted
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Button3.Enabled = False
End Sub
Again do the same for the following WebBrowser1_Navigated
Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
TextBox1.Text = WebBrowser1.Url.ToString()
Me.Text = WebBrowser1.DocumentTitle.ToString()
End Sub
Again do the same for the following WebBrowser1_Navigating
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
Button3.Enabled = True
End Sub
End Class
Finally double click the go button and write the following code in side button6_Click sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
0 comments:
Post a Comment