📄 frmkeys.frm
字号:
VERSION 5.00
Begin VB.Form frmKeys
AutoRedraw = -1 'True
Caption = "Fig. 12.13: Key Events"
ClientHeight = 3195
ClientLeft = 2535
ClientTop = 1590
ClientWidth = 4680
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
End
Attribute VB_Name = "frmKeys"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 12.13
' Demonstrating KeyDown, KeyUp, and KeyPress
Option Explicit ' General declaration
Dim mTitleString As String ' General declaration
Private Sub Form_Load()
' Store Caption value for use in KeyPress
mTitleString = Caption & Space$(5)
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
' Determine which, if any, of the Shift, Ctrl,
' or Alt keys is pressed
Select Case Shift
Case vbShiftMask ' Shift
ForeColor = vbYellow
Case vbAltMask ' Alt
ForeColor = vbRed
Case vbCtrlMask ' Ctrl
ForeColor = vbGreen
Case vbShiftMask + vbAltMask ' Shift + Alt
ForeColor = vbBlue
Case vbShiftMask + vbCtrlMask ' Shift + Ctrl
ForeColor = vbMagenta
Case vbAltMask + vbCtrlMask ' Alt + Ctrl
ForeColor = vbCyan
Case vbAltMask + vbCtrlMask + vbShiftMask ' All three
Call Cls
End Select
' Test for letter key
If KeyCode >= vbKeyA And KeyCode <= vbKeyZ Then
Print Chr$(KeyCode); ' Print the character
ElseIf KeyCode = vbKeyReturn Then ' Return key
Print ' Print on next line
End If
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
' Update title bar to display the key pressed
Caption = mTitleString & "(" & Chr$(KeyAscii) & ")"
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
' When key is released, change ForeColor to black
ForeColor = vbBlack
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -