hi all
i just want to alert when user hit "enter" key.
i tried this one in keyup event,
If e.KeyCode = Keys.Enter Then
MsgBox("msg")
End If
it didnt work, is that wrong ?
thx
hi all
i just want to alert when user hit "enter" key.
i tried this one in keyup event,
If e.KeyCode = Keys.Enter Then
MsgBox("msg")
End If
it didnt work, is that wrong ?
thx
It really depends what context you are applying to. The KeyUp event will only fire on a particular control, and bubble up to it's parent controls. However, if focus is not set on the control you are handling the event on then the event will not fire.
Just need to makes sure you put the code inside a sub that Handles Me.KeyDown
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
MsgBox("Enter Pressed")
End If
End Sub
The Enter key has strictly defined use in UI design, it executes the "accept" action of a dialog. In the designer, select the form and set the AcceptButton to your button. No code is required.
Note that the CancelButton has a similar usage, it is hard-wired to the Escape key.