Pregunta

Explanation to my Problem

I am making a project and placed a whole lot of graphical objects on it, including 2-3 buttons. On typing something, like pressing A , a particular set of commands should be executed. But this isn't working. I have put all the statements under form's KeyDown event.

I tried a lot, after removing all buttons, the statements written under the KeyDown event work (That is, the messagebox is shown). I think the error I am getting is because the form is not getting focus but there is no such command of setting focus to a form within a form, as far as I know.

  • How to detect KeyDown when there are other objects placed on the form to get focus?

Example Code

Private Sub Form1_KeyDown () Handles Me.KeyDown
    If e.KeyCode = Keys.A Then
        MsgBox("Success") 'Statement example
        'Other KeyDown statements
    End If
End Sub
¿Fue útil?

Solución

Try setting the forms KeyPreview property to true.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top