Search code examples
vb.netkeypress

How to detect keypress event?


MessageBox don't show when I click this form and pressed some button on keyboard.

Private Sub MainForm_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
    MessageBox.Show(e.KeyChar.ToString)
End Sub

Solution

  • set the KeyPreview property of the form to true