Question

I am trying to create a browser in Visual Studio 2013 using windows forms and the browser needs to have an Address bar that doubles as a Google Search bar like in Chrome. Here is my code for the Address bar, but I do not know what to put in after "If" and before "Then" in order to accomplish this. Any ideas?

 Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        If                Then
            AxWebBrowser1.Navigate(TextBox1.Text)
        Else
            AxWebBrowser1.Navigate("http://www.google.com/search?q=" + TextBox1.Text)
        End If
    End Sub

No correct solution

OTHER TIPS

You can use System.Uri.TryCreate to check that; I’d use UriKind.Absolute, though, because a lot of things are valid relative URIs.

Dim uri As Uri

If System.Uri.TryCreate(TextBox1.Text, UriKind.Absolute, uri) Then
    ' Navigate to it
Else
    ' Treat it as a search
End If

You could also make it a guess-free experience by requiring (or allowing) a prefix like ?, which is easily checked with s.StartsWith("?") and removed with s.Substring(1).

I just noticed the Ax prefix; if you’re using an ActiveX control,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top