求助:文本框输入2个数字后,光标自动跳到下个文本框

susan_0923 2008-01-09 10:35:12
我在Text1_Change里边写If Len(Text1.Text) >= 2 Then Text2.SetFocus
但是我如果在text1里输错了,想把第1个文本框里的2个数字选中直接改,光标就跳到第2个文本框里了,没法改.
应该怎么做呢?谢谢!
...全文
168 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
z_wenqian 2008-01-09
  • 打赏
  • 举报
回复
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text1.Text) > = 2 Then Text2.SetFocus
End Sub

Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = 2
End Sub
z_wenqian 2008-01-09
  • 打赏
  • 举报
回复

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text1.Text) > = 2 Then Text2.SetFocus
End Sub

Private Sub Text1_GotFocus()
Text1.SelStart = 1
Text1.SelLength = 2
End Sub
link_1 2008-01-09
  • 打赏
  • 举报
回复
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text1.Text) >= 2 Then Text2.SetFocus
End Sub

Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text2.Text) = 0 And KeyCode = vbKeyBack Then Text1.SelStart = Len(Text1.Text): Text1.SetFocus
End Sub
z_wenqian 2008-01-09
  • 打赏
  • 举报
回复
不要用Change事件,改用KeyUp

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text1) > = 2 Then Text2.SetFocus
End Sub



可以的,你试试
wh0588 2008-01-09
  • 打赏
  • 举报
回复
排除退格键或者keycode在数字或字母范围内(判断条件你自己看吧),然后再setfocus,这样就可以修改了
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode <> vbKeyBack And Len(Text1) >= 2 Then Text2.SetFocus
End Sub
susan_0923 2008-01-09
  • 打赏
  • 举报
回复
谢谢.但还是不能直接改第1个框里的2个数字,那光标跳到下个框了
caofusheng 2008-01-09
  • 打赏
  • 举报
回复
Private Sub Text1_Change()
If Len(Text1.Text) >= 2 Then Text2.SetFocus
End Sub

Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
z_wenqian 2008-01-09
  • 打赏
  • 举报
回复
不要用Change事件,改用KeyUp

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text1) >= 2 Then Text2.SetFocus
End Sub
susan_0923 2008-01-09
  • 打赏
  • 举报
回复
谢谢.但是我希望象输注册码那样,直接往下个文本框跳,不用打回车
zdingyun 2008-01-09
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text1) >= 2 Then
Text2.SetFocus
End If
End Sub

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧