0

When using the Form1.KeyDown, keystrokes don't seem to register.

For example, the Click works fine:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
        MsgBox("Hello")
    End Sub

That will display the message box when the form is clicked, but if you change it to:

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        MsgBox("Hello")
    End Sub

I can't seem to get the message box to appear.

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by makatzena
0

Hmn. The code looks right. I would try to change it from handling mybase though, to handling the form in question. I'm not sure if that will make a big difference or not, since I don't use .NET, but it would seem to me that the sub should handle keypress event of the form's name.

0

if you want it to work you will have to put the "keypreview" property of Form1 to true. This will make keyboard events be registered on the form.

In VB6 this same property made the form's keyboard events take priority from the other controls' keyboard events. It seems to have changed

saludos

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.