frmkeys.frm
来自「Visual Basic 6 大学教程的代码」· FRM 代码 · 共 78 行
FRM
78 行
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 + =
减小字号Ctrl + -
显示快捷键?