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 Private Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text1.SetFocus End Sub
Private Sub TxtUrl_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then sendkeys "{tab}" '下一个控件获得焦点 End If
End Sub
'放模块里,只要有KeyPress事件,本模块都可适用'敲Enter键转移焦点 Public Sub FocusNext(KeyCode As Integer) If KeyCode = 13 Then SendKeys "{tab}" End If
If KeyCode = Asc(vbCr) Then KeyCode = 0 End If End Sub'调用Private Sub TxtUrl_KeyPress(KeyAscii As Integer) call FocusNext(KeyAscii ) End Sub
If KeyAscii = 13 Then Text2.SetFocus
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text3.SetFocus
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text1.SetFocus
End Sub
sendkeys "{tab}" '下一个控件获得焦点
End If
End Sub
Public Sub FocusNext(KeyCode As Integer)
If KeyCode = 13 Then
SendKeys "{tab}"
End If
If KeyCode = Asc(vbCr) Then
KeyCode = 0
End If
End Sub'调用Private Sub TxtUrl_KeyPress(KeyAscii As Integer)
call FocusNext(KeyAscii )
End Sub
也即是模拟你按下了tab键,这样就能跳到下一个tabindex的控件上了楼上hhjjhjhj(大头)兄因此提醒你要依次设好TabIndex的值,免得跳错了
If KeyAscii = 13 Then SendKeys "{TAB}"
End Sub