Click here to Skip to main content
12,352,167 members (64,188 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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
vast25679
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 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 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.
—SA
rb_contra 6-Nov-13 12:02pm
   
Thanks....
   
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2016
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