2012-04-20 109 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