一种通用的方法: 设置窗体keypreview=true,在窗体的keypress中拦截enter。 Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then If TypeName(Me.ActiveControl) = "TextBox" Then KeyAscii = 0 SendKeys "{tab}" End If End If End Sub
private sub Text1_keypress(index as integer,keyascii as integer) if keyascii=13 and 条件 then text1(index+1).setFocus end sub
否则通过鼠标、或者按tab、或者通过代码转移焦点怎么办?
设置窗体keypreview=true,在窗体的keypress中拦截enter。
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
If TypeName(Me.ActiveControl) = "TextBox" Then
KeyAscii = 0
SendKeys "{tab}"
End If
End If
End Sub
if keyascii=13 and 条件 then text1(index+1).setFocus
end sub