按Enter键进入vb.net后如何进入下一个文本框 [英] How to go on next textbox after pressing enter in vb.net
问题描述
我想知道按Enter后如何聚焦另一个文本框。
表示如果我在textbox1上并按了回车那么我怎样才能按Enter键进入textbox2。?
这里我测试了代码你可以参考这个
私有 Sub txtUser_KeyDown( ByVal sender 作为 对象, ByVal e As System.Windows.Forms.KeyEventArgs)句柄 txtUser.KeyDown
如果 e.KeyCode = Keys.Enter 那么
txtPass.Focus()
结束 如果
结束 Sub
在用户输入用户名文本框的值后按ENTER键,它将重点关注密码文本框。
------
keyPress和keyDown事件之间存在差异 -
KeyPress事件不是由非字符键引发的;但是,非字符键会引发KeyDown和KeyUp事件。
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx [ ^ ]
你也可以使用SA建议的 KeyUp 事件。
希望它有所帮助。
使用Keypress event of TextBox
如果 e.KeyChar = Chr( 13 )然后
TextBox2.Focus
结束 如果跨度>
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.?
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.
use Keypress event of TextBox If e.KeyChar = Chr(13) Then TextBox2.Focus End If
这篇关于按Enter键进入vb.net后如何进入下一个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!