webbrowser: Url-bar + enter = navigate?

Untouchable

Member
Joined
Aug 6, 2006
Messages
11
Programming Experience
Beginner
Well, im working on a webbrowser but ive run into a peculiar thing...

Im trying to make it so that when you type in a address an hit enter, you will navigate to that address (I have a button that does this, but want to have both options)..

So far I have

VB.NET:
  Private Sub Text_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (e.KeyChar = Convert.ToChar(13)) Then
            activebrowser.Navigate(TextBox1.Text)
        End If
    End Sub

When i hit enter, nothing happens..
 
EDIT: also, i tried with
VB.NET:
 If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
and still nothing happened..

It may be worth noting that it isnt a textbox, but it is a ComboBox, does that make any difference?

EDIT2: this is just really strange, when i switched out 13 (enter) for 8 (backspace), it works.. wtf?
 
Last edited:
It's times like this when you wished you had read your post before posting it otherwise you make yourself look like a prat, just like i did right then. Sorry...

VB.NET:
e.keycode = keys.enter
 
Last edited:
VB.NET:
Private Sub Text_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  If Asc(e.KeyChar) = Keys.Enter Then activebrowser.Navigate(TextBox1.Text)
End Sub
or

VB.NET:
Private Sub Text_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
  If e.KeyCode = Keys.Enter Then activebrowser.Navigate(TextBox1.Text)
End Sub
 
Again, thanks for replies, but i think there is something wrong with my code somewhere else. I tried creating a new form and just tested it with a textbox and it worked. But for some reason it doesnt with my "real" form. Every other key works, but not enter (13). Cheers!
 
Back
Top