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

📄 form1.frm

📁 这里有很多很实用的VB编程案例,方便大家学习VB.
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "ListBox快速增量查询"
   ClientHeight    =   2805
   ClientLeft      =   1110
   ClientTop       =   1860
   ClientWidth     =   6780
   ClipControls    =   0   'False
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   8.25
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H80000008&
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2805
   ScaleWidth      =   6780
   Begin VB.ListBox ListBox1 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Height          =   1980
      Left            =   150
      Sorted          =   -1  'True
      TabIndex        =   0
      TabStop         =   0   'False
      Top             =   645
      Width           =   5100
   End
   Begin VB.TextBox txtSearch 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Height          =   300
      HideSelection   =   0   'False
      Left            =   1380
      MaxLength       =   65
      MousePointer    =   3  'I-Beam
      TabIndex        =   1
      Top             =   195
      Width           =   3840
   End
   Begin VB.CommandButton cmdClose 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "&Close"
      Height          =   330
      Left            =   5400
      TabIndex        =   3
      TabStop         =   0   'False
      Top             =   150
      Width           =   1200
   End
   Begin VB.Label Label1 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      BackStyle       =   0  'Transparent
      Caption         =   "查询文字:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   210
      Left            =   150
      TabIndex        =   2
      Top             =   255
      Width           =   1050
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit

Private Sub cmdClose_Click()
    End
End Sub


Private Sub Form_Load()
    Dim i As Integer
    Dim k As String

    For i = 1 To 22
        k = Chr(i + 64) & CStr(i)
        ListBox1.AddItem k
    Next i
    miNumKeys = 0
End Sub

Private Sub ListBox1_Click()
    Dim szListText As String
    Dim iListIndex As Integer
    On Error Resume Next

    If ListBox1.ListIndex >= 0 And miCtrlFocus = LISTBOX_FOCUS Then
        iListIndex = ListBox1.ListIndex
        szListText = ListBox1.List(iListIndex)
        txtSearch.Text = szListText
    End If
End Sub

Private Sub ListBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    miCtrlFocus = LISTBOX_FOCUS
    miNumKeys = 0
End Sub



Private Sub txtSearch_Change()
  Dim szSrchText As String
  Dim iTxtLen As Integer
  Dim iListIndex As Integer
  Dim fReturn As Integer
  
  On Error Resume Next

  If miCtrlFocus = TEXTBOX_FOCUS And mfKeepKey And Not mfScrolling Then
    iTxtLen = Len(txtSearch.Text)
    If iTxtLen Then
      miNumKeys = IIf(miNumKeys < iTxtLen, miNumKeys, iTxtLen)
      szSrchText = txtSearch.Text
      fReturn = SearchListBox(szSrchText, ListBox1, iListIndex)
      
      mfScrolling = True
      If iListIndex = -1 Then
        ListBox1.ListIndex = -1
      Else
        ListBox1.Selected(iListIndex) = True
        txtSearch = ListBox1.List(ListBox1.ListIndex)
        txtSearch.SelStart = miNumKeys
        txtSearch.SelLength = (Len(txtSearch.Text) - miNumKeys)
      End If
      mfScrolling = False
    End If
  End If
End Sub

Private Sub txtSearch_GotFocus()
  miNumKeys = 0
  txtSearch.SelStart = 0
  txtSearch.SelLength = Len(txtSearch.Text)
End Sub

Private Sub txtSearch_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = KEY_BACK Or KeyCode = KEY_DELETE Or KeyCode = KEY_CLEAR Then
    mfKeepKey = False
    If KeyCode = KEY_BACK Then
      ListBox1.ListIndex = -1
    End If
  Else
    mfKeepKey = True
  End If
End Sub

Private Sub txtSearch_KeyPress(KeyAscii As Integer)
    miCtrlFocus = TEXTBOX_FOCUS
    If mfKeepKey Then
        miNumKeys = Len(txtSearch.Text) + 1
    End If
End Sub

⌨️ 快捷键说明

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