'组合框列表增量查找(英文好用) Public Sub ComboIncrementalSearch(cbo As _ ComboBox, KeyAscii As Integer) Static dTimerLast As Double Static sSearch As String Static hWndLast As Long Dim nRet As Long Const MAX_KEYPRESS_TIME = 0.5 ' Weed out characters that are not scanned If (KeyAscii < 32 Or KeyAscii > 127) _ Then Exit Sub If (Timer - dTimerLast) < _ MAX_KEYPRESS_TIME And hWndLast = _ cbo.hWnd Then sSearch = sSearch & Chr$(KeyAscii) Else sSearch = Chr$(KeyAscii) hWndLast = cbo.hWnd End If ' Search the combo box nRet = SendMessage(cbo.hWnd, _ CB_FINDSTRING, -1, ByVal sSearch) If nRet >= 0 Then cbo.ListIndex = nRet End If KeyAscii = 0 dTimerLast = Timer End Sub
中文,试试: Private Declare Function SendMessagebyString Lib _ "user32" Alias "SendMessageA" (ByVal hWND As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ ByVal lParam As String) As LongPrivate Const LB_FINDSTRINGEXACT = &H1A2 '在 ListBox 中精确查找 Private Const CB_FINDSTRINGEXACT = &H158 '在 ComboBox 中精确查找 Private Const LB_FINDSTRING = &H18F '在 ListBox 中模糊查找 Private Const CB_FINDSTRING = &H14C '在 ComboBox 中模糊查找Private Combo1_Change() Dim n As Longn = SendMessagebyString(Combo1.hWnd, CB_FINDSTRING, -1, Combo1.Text) If n >= 0 Then Combo1.ListIndex = nEnd Sub
Public Sub ComboIncrementalSearch(cbo As _
ComboBox, KeyAscii As Integer)
Static dTimerLast As Double
Static sSearch As String
Static hWndLast As Long
Dim nRet As Long
Const MAX_KEYPRESS_TIME = 0.5
' Weed out characters that are not scanned
If (KeyAscii < 32 Or KeyAscii > 127) _
Then Exit Sub
If (Timer - dTimerLast) < _
MAX_KEYPRESS_TIME And hWndLast = _
cbo.hWnd Then
sSearch = sSearch & Chr$(KeyAscii)
Else
sSearch = Chr$(KeyAscii)
hWndLast = cbo.hWnd
End If
' Search the combo box
nRet = SendMessage(cbo.hWnd, _
CB_FINDSTRING, -1, ByVal sSearch)
If nRet >= 0 Then
cbo.ListIndex = nRet
End If
KeyAscii = 0
dTimerLast = Timer
End Sub
Private Declare Function SendMessagebyString Lib _
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As LongPrivate Const LB_FINDSTRINGEXACT = &H1A2 '在 ListBox 中精确查找
Private Const CB_FINDSTRINGEXACT = &H158 '在 ComboBox 中精确查找
Private Const LB_FINDSTRING = &H18F '在 ListBox 中模糊查找
Private Const CB_FINDSTRING = &H14C '在 ComboBox 中模糊查找Private Combo1_Change()
Dim n As Longn = SendMessagebyString(Combo1.hWnd, CB_FINDSTRING, -1, Combo1.Text)
If n >= 0 Then Combo1.ListIndex = nEnd Sub