I am working on a web browser for fun and to get a little more acquainted with VB. I felt lost during school this past year and wanted to do something that sounded like fun. Ok, enough of that.

When I put in my code to just press enter after inserting the desired URL nothing happens. It worked the first time I did it then I started adding code for other things and now it won't work. Here is my code.

Private Sub txtNav_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            WebBrowser1.Navigate(txtNav.Text)
        End If
    End Sub

I don't understand why it would just not work now after it worked before adding other coding for buttons etc. Any help would be appreciated. I don't want code per se, just an idea of where I went wrong and if there is something else to be added to make it work. It's really just a simple browser I am doing.

Thanks.

Handles clause is missing.

Private Sub txtNav_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNav.KeyDown
        If e.KeyCode = Keys.Enter Then
            WebBrowser1.Navigate(txtNav.Text)
        End If
    End Sub

try this

Private Sub txtNav_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNav.KeyDown
        If e.KeyCode = Keys.Enter Then
           WebBrowser1.Url = New System.Uri(txtNav.Text, System.UriKind.Absolute)
        End If
    End Sub

Yep it worked after putting in the Handles clause. I don't know how I missed that. I must have looked at it 100 times. Anyway, thanks for the help/replies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.