How to intercept capture TAB key in WinForms application?

前端 未结 4 1784
孤城傲影
孤城傲影 2021-01-17 15:00

I\'m trying to capture the Tab key in a Windows Forms application and do a custom action when it is pressed.

I have a Form with several listViews and button

4条回答
  •  [愿得一人]
    2021-01-17 15:41

    will this help you?

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
      Dim keyPressed As Keys = CType(msg.WParam.ToInt32(), Keys)
    
      Select Case keyPressed
        Case Keys.Right msgbox("Right Arrow Key Caught")
        Case Keys.Left msgbox("LeftArrow Key Caught")
        Case Keys.Up msgbox("Up Arrow Key Caught")
        Case Keys.Down msgbox("Down Arrow Key Caught")
        Case Else Return MyBase.ProcessCmdKey(msg, keyData)
      End Select
    End Function 
    

提交回复
热议问题