Public Class frmTestKey
Private Sub txtTestRegion_KeyDown(ByVal sender As System.Object,_
ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTestRegion.KeyDown
'<Shift>+<Ctrl>+<...>组合测试
If e.Shift And e.Control Then
Select Case e.KeyCode
Case Keys.F1
MsgBox("按<Shift>+<Ctrl>+<F1>")
Case Keys.F2
MsgBox("按<Shift>+<Ctrl>+<F2>")
End Select
Exit Sub
End If
'<Shift>+<...>组合测试
If e.Shift Then
Select Case e.KeyCode
Case Keys.Home
MsgBox("按<Shift>+<HOME>")
Case Keys.End
MsgBox("按<Shift>+<END>")
End Select
Exit Sub
End If
'<Ctrl>+<...>组合测试
If e.Control Then
Select Case e.KeyCode
Case Keys.Add
MsgBox("按<Ctrl>+<+>")
Case Keys.Subtract
MsgBox("按<Ctrl>+<->")
End Select
Exit Sub
End If
'<Alt>+<...>组合测试
If e.Alt Then
Select Case e.KeyCode
Case Keys.Multiply
MsgBox("按<Alt>+<*>")
Case Keys.Divide
MsgBox("按<Alt>+</>")
End Select
Exit Sub
End If
'<...>测试
Select Case e.KeyCode
Case Keys.Left
MsgBox("按<←>")
Case Keys.Right
MsgBox("按<→>")
End Select
lblKeyOther.Text = e.KeyCode
End Sub
Private Sub txtTestRegion_KeyUp(ByVal sender As System.Object,_
ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTestRegion.KeyUp
'<Shift>+<Ctrl>+<...>组合测试
If e.Shift And e.Control Then
Select Case e.KeyCode
Case Keys.F3
MsgBox("松<Shift>+<Ctrl>+<F3>")
Case Keys.F4
MsgBox("松<Shift>+<Ctrl>+<F4>")
End Select
Exit Sub
End If
'<Shift>+<...>组合测试
If e.Shift Then
Select Case e.KeyCode
Case Keys.PageDown
MsgBox("松<Shift>+<PageDown>")
Case Keys.PageUp
MsgBox("松<Shift>+<PageUp>")
End Select
Exit Sub
End If
'<Ctrl>+<...>组合测试
If e.Control Then
Select Case e.KeyCode
Case Keys.Delete
MsgBox("松<Ctrl>+<Delete>")
Case Keys.Insert
MsgBox("松<Ctrl>+<Insert>")
End Select
Exit Sub
End If
'<Alt>+<...>组合测试
If e.Alt Then
Select Case e.KeyCode
Case Keys.D1
MsgBox("松<Alt>+<1>")
Case Keys.D2
MsgBox("松<Alt>+<2>")
End Select
Exit Sub
End If
'<...>测试
Select Case e.KeyCode
Case Keys.Up
MsgBox("松<↑>")
Case Keys.Down
MsgBox("松<↓>")
End Select
End Sub
End Class
原文链接:https://www.f2er.com/vb/260995.html