短按Ctrl + - 不工作vb

时间:2012-04-20 22:10:14

标签: vb.net keyboard-shortcuts

我有以下代码:

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 + - ),它永远不会被捕获!

1 个答案:

答案 0 :(得分: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