user3197661
user3197661

Reputation: 47

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

Upvotes: 1

Views: 980

Answers (2)

Ramesh Yadav
Ramesh Yadav

Reputation: 153

change Me.KeyPress to MyBase.KeyPress ... this will work

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

Upvotes: 1

Monah
Monah

Reputation: 6784

set the KeyPreview property of the form to true

Upvotes: 1

Related Questions