请教如何捕捉按键

nuinui 2000-05-29 09:48:00
请教如何捕捉按键。现有几个TextBox文本框,用于输入数据,当输入完一个后按Enter光标就自动跳到下一个文本框。请问如何编写该段程序?
...全文
193 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jing 2000-06-01
  • 打赏
  • 举报
回复
1.设定TabIndex

2.当接收到回车后 SendKeys "tab"
cxs 2000-06-01
  • 打赏
  • 举报
回复
只要在触发事件选项里,选择KeyDown,再编写相应的程序就可以了。
Un1 2000-05-30
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
SendKeys vbTab, True
End If
End Sub
ring 2000-05-30
  • 打赏
  • 举报
回复
他们的方法都是有几个文本框就要写几遍,我的只要写一遍,呵呵
先把Form1的KeyPreview属性设为True,然后贴上以下代码
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
SendKeys vbTab
End If
End Sub
你可以按照你的需求再改巴改巴
Wonny 2000-05-30
  • 打赏
  • 举报
回复
定义一个全局变量 counter
dim counter as integer
counter=0
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
text(counter).setfocus
counter=iif(counter>MAXCounter,0,counter+1)
或 counter=counter+1
if counter>max then
...
end if
End If
End Sub
您根据需要添加即可。
qyx888 2000-05-29
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Text2.SetFocus
'以下代码使文本框中的所有内容被选中
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End If
End Sub
常数vbKeyReturn请在帮助中查找关键字为"Keycode常数"的帮助项.
yangpo 2000-05-29
  • 打赏
  • 举报
回复
sub txtYear_KeyDown(KeyCode as integer)
if keycode=13 then
txtMon.setfouse
end if
end sub

7,759

社区成员

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

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