I added 2 textboxes on the form and runs it...I pressed the enter after I type in simple text.. it will not goto next textbox but tab can do .. why ... no nay code.. strange....
Thanks

Recommended Answers

All 7 Replies

I added 2 textboxes on the form and runs it...I pressed the enter after I type in simple text.. it will not goto next textbox but tab can do .. why ... no nay code.. strange....
Thanks

Hi,

You can try something like this:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox2.Text = TextBox1.Text
        End If

    End Sub

If what you're trying to do is to have the "enter" key behave in the same way as the "tab" key (from what I read, it is not "recommended") you might want to try this :

Private Sub txtBase_KeyPress(ByVal sender As Object, ByVal e As system.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar = vbCr Then
            SendKeys.Send(vbTab)
        End If
    End Sub

I have not yet found a way to get rid of the beep. Looking disparately though.

I just want it simple react like VB6, press the enter key after I finished enter the text then focus will jump to next textbox. that's it. isn't this a standard function that textbox should react ??? I use VB 2005 express..
Thanks ...

Hi,

Then you can try this:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox2.Focus()
        End If

    End Sub

Thank you Luc001,
it works, but this is doesn't make any sense to me, I thought change to next control after you press enter is intrinsic function ??? do I have to write this code in every textbox ??? is this happen to everyone ?? or just me ??
Thanks

Actually this is how things work but still you don't have to write this for every control, just handle it by every control you need to apply enter key one ex:

Private Sub EnterKey(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
    Handles TextBox1.KeyPress, TextBox2.KeyPress

        If e.KeyChar = Chr(13) Then SendKeys.Send(vbTab)

    End Sub

So this sub will be applied for textbox1, textbox2 and any other control that you add and has a keypress event.
No language is perfect.

Thank you very much, I thought that was my mistake some where... if that is because the VB lacked of this function, I just have to put up with that.. thank you again...

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.