只要用鼠标点一下按钮就相当用手敲了一下回车键,请问各位大侠该如何实现?
Private Sub Command1_Click()
SendKeys "{1}"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
ElseIf KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
Label3.Caption = "ID号必须由数字构成"
End If
End Sub
Private Sub Text1_LostFocus()
If Len(Text1.Text) < 10 Then
Label3.Caption = "ID号必须由10位数构成"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
Else
Label3.Caption = ""
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Text2.Text <> "000000" Then
Label3.Caption = "密码错误,请重新输入!"
Text2.SelStart = 0
Text2.SelLength = Len(Text2)
Else
Label3.Caption = "欢迎" & Text1.Text & "用户登录!"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
End If
End Sub点击按钮后无法登录!
VB问题:如何用按钮控件代替键盘上的回车键?
答案:4 悬赏:20
解决时间 2021-12-29 08:19
- 提问者网友:无悔疯狂
- 2021-12-28 14:58
最佳答案
- 二级知识专家网友:厭世為王
- 2021-12-28 16:11
Private Sub Command1_Click()
Text2.SetFocus
SendKeys chr(13)
End Sub
Text2.SetFocus
SendKeys chr(13)
End Sub
全部回答
- 1楼网友:恕我颓废
- 2021-12-28 18:56
用win32API中的postmessage()方法,给指定窗口发送键盘消息即可以实现
- 2楼网友:24K纯糖
- 2021-12-28 18:02
用timer控件实现,拖动 timer(时间)控件 到form里,设置控件属性interval(延迟 2次活动之间的间隔)=你2次按enter键的间隔时间,具体代码如下:
dim i as long
private sub form_load()
timer1.interval = 500
end sub
private sub timer1_timer()
i = i + 1
if i = 60 or 1 then
sendkeys chr(13)
if i = 60 then
i = 0
end if
end if
end sub
- 3楼网友:余生继续浪
- 2021-12-28 17:15
sendkeys "{?}" 注:?为按键名称,如abc f1 等。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯