The following code shows you how to make a simple webbrowser. For this you have to use a tool item webbrowser from toolbox , where the site is loaded.
' btnGo working
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
WebBrowser1.Navigate(TextBox1.Text, False)
End Sub
' btnForward working
Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
WebBrowser1.GoForward()
End Sub
' btnBack working
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
WebBrowser1.GoBack()
End Sub
' If user press enter after writing website address
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 13 Then
btnGo_Click(sender, e)
End If
End Sub
This following function is for getting keypressed by user and do the mentioned below tasks.
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (Keys.Control Or Keys.Right) Then ' if (ctrl + right) press then goForward
WebBrowser1.GoForward()
ElseIf keyData = (Keys.Back) Then ' if backspace keypress then goBack
WebBrowser1.GoBack()
ElseIf keyData = (Keys.Control Or Keys.Enter) Then ' if (ctrl + enter) press then load the site
WebBrowser1.Navigate("http://" & TextBox1.Text & ".com", False)
TextBox1.Text = "http://www." & TextBox1.Text & ".com"
End If
End Function
0 comments:
Post a Comment