如何检测按键事件?

时间:2014-02-02 07:56:57

标签: vb.net keypress

当我单击此表单并按下键盘上的某个按钮时,

MessageBox不会显示。

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

2 个答案:

答案 0 :(得分:1)

将表单的KeyPreview属性设置为true

答案 1 :(得分:1)

Me.KeyPress更改为MyBase.KeyPress ...这将有效

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