⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmkeypreview.frm

📁 Visual Basic 6 大学教程的代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmKeyPreview 
   Caption         =   "Fig. 12.14: KeyPreview"
   ClientHeight    =   1065
   ClientLeft      =   2460
   ClientTop       =   2745
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   1065
   ScaleWidth      =   4680
   Begin VB.TextBox txtInput 
      CausesValidation=   0   'False
      Height          =   495
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   4335
   End
End
Attribute VB_Name = "frmKeyPreview"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 12.14
' Demonstrating the KeyPreview property.
Option Explicit            ' General declaration

Private Sub Form_Load()
   Call Randomize
   
   ' Allow Form to get key events first
   KeyPreview = True
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
      
   ' Only allow numeric keys
   If KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Then
      txtInput.Text = txtInput.Text & Chr$(KeyAscii)
   End If
   
End Sub

Private Sub txtInput_KeyPress(KeyAscii As Integer)
   KeyAscii = 0   ' Disable event handling
End Sub

Private Sub txtInput_KeyUp(KeyCode As Integer, Shift As Integer)
   
   Select Case Int(Rnd() * 3)
      Case 0
         txtInput.BackColor = vbYellow
      Case 1
         txtInput.BackColor = vbCyan
      Case 2
         txtInput.BackColor = vbRed
   End Select
   
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -