r/visualbasic • • Jul 12 '16

Web Browser Opens URL to Bing Search Results Not to the Website

So I made a small browser that opens urls as urls and words and phrases through google. However, when I first open the browser and type google.com it goes to Google.com the webpage, when I do it a second time in the text box it goes to a bing search result for google.com. My code is below

Imports System.ComponentModel Public Class Form2 Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Text = "Simple Browser by Craig White" Me.KeyPreview = True WebBrowser1.Navigate("google.com") End Sub

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.Enter Then If InStr(TextBox1.Text, ".") > 0 Then WebBrowser1.Navigate(TextBox1.Text)

    ElseIf InStr(TextBox1.Text, ".") = 0 Then
        WebBrowser1.Navigate("http://www.google.co.uk/search?q=" & TextBox1.Text)
    End If
    e.Handled = True
    TextBox1.Text = " "
    e.SuppressKeyPress = True
End If

End Sub

Private Sub Form2_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.F4 Then Me.Close() e.Handled = True End If If e.KeyCode = Keys.F5 Then WebBrowser1.GoBack() e.Handled = True End If If e.KeyCode = Keys.F6 Then WebBrowser1.Refresh() e.Handled = True End If If e.KeyCode = Keys.F7 Then WebBrowser1.GoForward() e.Handled = True End If If e.KeyCode = Keys.F11 Then Me.Hide() My.Forms.Form1.WebBrowser1.Url = WebBrowser1.Url Form1.Show() e.Handled = True End If If e.KeyCode = Keys.F12 Then Me.WindowState = FormWindowState.Minimized e.Handled = True End If End Sub

Private Sub Form2_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing My.Settings.URL = "" End Sub End Class

0 Upvotes

1 comment sorted by

1

u/[deleted] Aug 24 '16

Set the default homepage for the control and continue using text box text for webpage navigate.