Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
vast25479
Rate this: bad
good
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
        txtPass.Focus()
    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.
 

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx[^]
 
U can also use KeyUp event as SA suggested.
 
Hope it helps.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

 
use Keypress event of TextBox
 
If e.KeyChar = Chr(13) Then
   TextBox2.Focus
End If
  Permalink  
v3
Comments
Sergey Alexandrovich Kryukov at 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.
—SA
Member 10331842 at 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 at 17-Jan-13 1:04am
   
why i cant use Keypress event...??
Sergey Alexandrovich Kryukov at 17-Jan-13 1:17am
   
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.
—SA
rb_contra at 6-Nov-13 12:02pm
   
Thanks....
Sergey Alexandrovich Kryukov at 6-Nov-13 12:07pm
   
You are welcome.
—SA

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

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,280
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
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