他们的方法都是有几个文本框就要写几遍,我的只要写一遍,呵呵
先把Form1的KeyPreview属性设为True,然后贴上以下代码
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys vbTab
End If
End Sub
你可以按照你的需求再改巴改巴
定义一个全局变量 counter
dim counter as integer
counter=0
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
text(counter).setfocus
counter=iif(counter>MAXCounter,0,counter+1)
或 counter=counter+1
if counter>max then
...
end if
End If
End Sub
您根据需要添加即可。
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Text2.SetFocus
'以下代码使文本框中的所有内容被选中
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End If
End Sub
常数vbKeyReturn请在帮助中查找关键字为"Keycode常数"的帮助项.