把该按钮的default属性设为true.任何时候只要按回车键,这个按键就会被触发。
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox (KeyCode)
End Sub
Private Sub Form_Load()
Form1.KeyPreview = True
End Sub
这代码可以实现你的功能,任何时候按键都有效果。
在VB里使用AcceptButton函数来设定一个按钮恒为默认按钮。
设定默认按钮:
Me.AcceptButton = Me.btnLogin(想要设定的按钮名称)。
把所有其它控件的点击事件里加入一条command1.SetFocus如:
Private Sub Form_Load()
...
command1.SetFocus
End Sub
Private Sub command2_click()
...
command1.SetFocus
Private Sub Form_click()
...
command1.SetFocus
End Sub
End Sub
......
.......
这样就可以了~~