Capturing Arrow Keys in a Custom Control

Joined
Apr 6, 2006
Messages
3
Reaction score
0
I am trying to make a custom control in which you can move a point around using the arrow keys. To test it out I have put the control on a form which also contains several buttons.

I have added a KeyDown event handler to the custom control (see code below). It responds fine to keys like Enter or Shift-X, but not to the arrow keys. Pressing an arrow key just jumps from one button to the next on the form.

In fact, I'd like to handle all possible key combinations in my control, not in the form. Can anyone tell me how?

thanks, BB



Private Sub Drawing_Sheet_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Left
m_PointLocation.X -= 1
Case Keys.Right
m_PointLocation.X += 1
Case Keys.Up
m_PointLocation.Y -= 1
Case Keys.Down
m_PointLocation.Y += 1

'tests:
Case Keys.Enter
MsgBox("Enter pressed")
Case Keys.X
If e.Modifiers = Keys.Shift Then MsgBox("Shift x pressed") Else MsgBox("x pressed")
End Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top