Click here to Skip to main content
12,954,522 members (56,194 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to know that How to focus another textbox after pressing enter.
Means if i am on textbox1 and i press enter then How i can go to textbox2 by pressing enter.?
Posted 16-Jan-13 9:11am
Updated 20-May-17 0:58am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Here i have tested code u can refer this

Private Sub txtUser_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUser.KeyDown
    If e.KeyCode = Keys.Enter Then
    End If
End Sub

after entering the value to Username textbox as soon the user press ENTER , it will focus to Password textbox.

There is a difference between keyPress and keyDown event-
The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.[^]

U can also use KeyUp event as SA suggested.

Hope it helps.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

use Keypress event of TextBox
If e.KeyChar = Chr(13) Then
End If
Sergey Alexandrovich Kryukov 16-Jan-13 17:31pm
No, it should be KeyDown (or KeyUp), to use Keys.Return... This is really a bad way to do things.
Member 10331842 26-Oct-13 4:42am
how can i use textbox as label with it is fuction example when run a project to display enter your name here when clicked to clear an if clear the text to display default text ?
rb_contra 17-Jan-13 1:04am
why i cant use Keypress event...??
Because Enter is not a key... (sounds weird, but this is because API terminology is weird). Enter is correctly described as Keys.Return, passed as the parameter to KeyUp or KeyDown, not KeyPress. Look at the event args types and properties of those types.
rb_contra 6-Nov-13 12:02pm
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,143
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 20 May 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100