请问大哥这怎么编码 vb

来源:百度知道 编辑:UC知道 时间:2024/06/03 03:28:29
当焦点落在text1时
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
If Text2.Visible = True Then
Text2.SetFocus
Else
Text1.SetFocus
End If
If Option1.Value = True Then
Option2.Value = True
Else
Option1.Value = True
End If
End If
end sub
当焦点落在text2上时
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii =9 Then
If Text3.Visible = True Then
Text3.SetFocus
Else
Text1.SetFocus
End If
End If
End Sub
当焦点落在text3上时
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
Text1.SetFocus
End If
End Sub
补充说明,不能用lostfocus事件
把forml.keypreview的属性变为True时,也不发生。请各位指教
用Keydown也不行啊

嗯,明白了,问题在于按TAB时,自动跑焦点了……
这个问题是比较棘手的。我想了个方案,保证可以抓住Tab键的信息,但不敢保证没其他副作用。
就是把窗口上其他所有控件,只要有tabstop属性的,都改成false,就是让它们不接受Tab键,这就行了。

至于KeyPress还是Keydown,再验证一下那个才是。我记得一些按键是不能用KeyPress或Keydown的