KeyDown event not firing with .NET WinForms?

后端 未结 2 546
野趣味
野趣味 2020-12-07 01:11

I already have KeyPreview set to true in the form properties

I\'m working on a small program, and I\'m having a problem where it seems

相关标签:
2条回答
  • 2020-12-07 02:01

    Some controls intercept the arrow keys in the keydown event, but not in the keyup event. One solution is to derive the control class and override ProcessCmdKey:

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keydata As Keys) As Boolean
    
    If keydata = Keys.Right Or keydata = Keys.Left Or keydata = Keys.Up Or keydata = Keys.Down Then
      OnKeyDown(New KeyEventArgs(keydata))
      ProcessCmdKey = True
    Else
      ProcessCmdKey = MyBase.ProcessCmdKey(msg, keydata)
      End If
    End Function
    
    0 讨论(0)
  • 2020-12-07 02:03

    No need to do so much just use Me.KeyPreview = True in load function and use (Handles Me.KeyUp) in Target function for vb.net for arrow keys

    0 讨论(0)
提交回复
热议问题