2012-04-20 55 views
2

我有以下代码:短键按Ctrl + - 工作不动

Private Sub myGrid_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myGrid.KeyDown 
    If e.KeyCode = Keys.Divide AndAlso e.Control Then 
     Dim response = MsgBox("are you sure to delete a record?", vbYesNo) 
     If response = vbYes Then 
      //Delete the record 
     End If 
    End If 
End Sub 

此作品(对于按Ctrl + /),但问题是,这适用于任意键不同于- 。如果我指定Keycode是Keys.Subtract(要使用Ctrl + -)它永远不会被捕获!

+0

答案有帮助吗? – Abraham 2013-02-22 06:00:44

回答

0

“ - ”的KeyCode是Keys.OemMinus。使用Debug.WriteLine(e.KeyCode.ToString())来测试您按下的键。以下作品适用于我:

Private Sub myGrid_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myGrid.KeyDown 
    If e.KeyCode = Keys.OemMinus AndAlso e.Control Then 
     Dim response = MsgBox("are you sure to delete a record?", vbYesNo) 
     If response = vbYes Then 
      '//Delete the record 
     End If 
    End If 
    Debug.WriteLine(e.KeyCode.ToString()) 
End Sub