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

📄 start.frm

📁 控件大小自动随窗体变化
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Dyn Combo Srch"
   ClientHeight    =   1815
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   2775
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   1815
   ScaleWidth      =   2775
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2 
      Caption         =   "Add Item"
      Height          =   315
      Left            =   1560
      TabIndex        =   3
      Top             =   1440
      Width           =   1155
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Delete"
      Height          =   315
      Left            =   1560
      TabIndex        =   2
      Top             =   540
      Width           =   1155
   End
   Begin VB.TextBox Text1 
      Height          =   315
      Left            =   120
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   1020
      Width           =   2595
   End
   Begin VB.ComboBox Combo1 
      Height          =   315
      ItemData        =   "Start.frx":0000
      Left            =   120
      List            =   "Start.frx":0016
      TabIndex        =   0
      Text            =   "Combo1"
      Top             =   120
      Width           =   2595
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private lastDelOp As Boolean

Private Sub Combo1_Change()
'change made by me flag
Static ChangeFlag As Boolean

'if change is made by the user
If Not ChangeFlag Then

Dim cboText As String
Dim lencboText As Integer
Dim tmpLen As Integer
Dim tmp As Integer

'init variables
cboText = Combo1.Text
lencboText = Len(Combo1.Text)

'if the last operation has not been deletion
If Not lastDelOp Then

'check if user entry matches an item
For tmp = 0 To Combo1.ListCount - 1
 If UCase(Left(Combo1.Text, Combo1.SelStart)) = UCase(Combo1.List(tmp)) Then
  'the change that follows is made by me, so set flag
  ChangeFlag = True
  Combo1.Text = Combo1.List(tmp)
  Combo1.SelStart = Len(Combo1.Text)
  'reset flag
  ChangeFlag = False
  'reset deltion operation flag
  lastDelOp = False
  Exit Sub
 End If
Next tmp

'if you omit this check, when you delete the text in
'the cbobox the first item will be automaticall
'displayed
'if not just cleared
If lencboText > 0 Then
 'loop to check all items
 For tmp = 0 To Combo1.ListCount - 1
  'if fisrt letters of current item match the cbotext
  'if you omit ucase the search will be case sensitive
  If UCase(Left(Combo1.List(tmp), lencboText)) = UCase(cboText) Then
   'save entered text length
   tmpLen = lencboText
   'set new text - the cbobox item
   ChangeFlag = True
   Combo1.Text = Combo1.List(tmp)
   'select all letters after those the user entered
   Combo1.SelStart = tmpLen
   Combo1.SelLength = Len(Combo1.List(tmp)) - tmpLen
   ChangeFlag = False
   'exit the loop
   Exit For
  End If
 Next tmp
End If 'lencboText > 0

End If 'Not lastDelOp
'reset flag
lastDelOp = False
End If 'Not ChangeFlag
End Sub

Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
'if delete or backspace pressed - pull up flag
If (KeyCode = vbKeyDelete) Or (KeyCode = vbKeyBack) Then
 lastDelOp = True
End If
End Sub

Private Sub Command1_Click()
If Combo1.ListIndex <> -1 Then
 Combo1.RemoveItem Combo1.ListIndex
End If
End Sub

Private Sub Command2_Click()
Combo1.AddItem Text1.Text
Text1.Text = ""
End Sub

⌨️ 快捷键说明

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