设置 Form1.KeyPreview=True Private Sub Form_KeyPress(KeyAscii As Integer) If ascii = 13 Then Call 确定_click End If End Sub
如果你的Text不是空间数组那你在每个Text_KeyDown里调用WhenOKclick函数, 如果是使用了数组,那就方便多了 Function WhenOKclick(keycode as Integer) if keycode = 13 then OK_Click '这是确定按钮的Click事件 End If End Function Private Sub OK_Click() MsgBox "确定按钮已经按下" End Sub
但是奇怪的是当焦点在其他按钮控件时这个就无效了,不知道为什么。
哪位大侠知道的?
Private Sub Form_KeyPress(KeyAscii As Integer)
If ascii = 13 Then
Call 确定_click
End If
End Sub
如果是使用了数组,那就方便多了
Function WhenOKclick(keycode as Integer)
if keycode = 13 then
OK_Click '这是确定按钮的Click事件
End If
End Function
Private Sub OK_Click()
MsgBox "确定按钮已经按下"
End Sub