vb2008中按下“enter”相当于按下“tab”怎么实现

来源:百度知道 编辑:UC知道 时间:2024/05/16 06:12:25
有TextBox1.....TextBoxN这N个文本框
怎么实现按上“Enter”光标跳到下一个文本框中?
错误 1 “SetFocus”不是“System.Windows.Forms.TextBox”的成员

VB2008里没有SetFocus 这一项

你最好把这N个文本框做成控件数组,这样只需要写一句代码就可以完成。如下:
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then Text1(Index + 1).SetFocus
End Sub

否则你需要在每个文本框的keypress中都写上相应的代码。如下:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text2.SetFocus
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text3.SetFocus
End Sub
以此类推。

My.Computer.Keyboard.SendKeys("{tab}")