2

我有以下代码:

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+ -)它永远不会被抓住!

4

1 回答 1

0

“-”的键码是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
于 2012-04-28T01:14:30.897 回答