好久没有贴过代码了...贴一段,参考一下(在窗体上放几个TEXTBOX),然后,COPY下面代码即可:Option ExplicitDim WithEvents Ev_Text As VB.TextBox Dim WithEvents smTimer As Timer Dim M_NewActCon As ObjectPrivate Sub Ev_Text_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 SendKeys "{TAB}" End If End SubPrivate Sub Form_Load() If smTimer Is Nothing Then Set smTimer = Me.Controls.Add("VB.Timer", "smTimer", Me) smTimer.Interval = 50 smTimer.Enabled = True End If End SubPrivate Sub smTimer_Timer() Static NewName As String Static OleName As String
Set M_NewActCon = Me.ActiveControl NewName = M_NewActCon.Name If NewName <> OleName Then If UCase$(TypeName(M_NewActCon)) = "TEXTBOX" Then Set Ev_Text = M_NewActCon End If End If End Sub
Dim WithEvents smTimer As Timer
Dim M_NewActCon As ObjectPrivate Sub Ev_Text_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys "{TAB}"
End If
End SubPrivate Sub Form_Load()
If smTimer Is Nothing Then
Set smTimer = Me.Controls.Add("VB.Timer", "smTimer", Me)
smTimer.Interval = 50
smTimer.Enabled = True
End If
End SubPrivate Sub smTimer_Timer()
Static NewName As String
Static OleName As String
Set M_NewActCon = Me.ActiveControl
NewName = M_NewActCon.Name
If NewName <> OleName Then
If UCase$(TypeName(M_NewActCon)) = "TEXTBOX" Then
Set Ev_Text = M_NewActCon
End If
End If
End Sub
http://community.csdn.net/Expert/topic/3353/3353756.xml?temp=.6370966
或者设置同样的属性啊