新建From1(窗体),新建Text1(TextBox),List1(ListBox),代码:
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Function ListboxFindString(sSearchString As String, lHwndListbox As Long) As Long
Const LB_FINDSTRING = &H18F
ListboxFindString = SendMessage(lHwndListbox, LB_FINDSTRING, -1, ByVal sSearchString)
End Function
Private Sub Text1_Change()
Me.List1.ListIndex = ListboxFindString(Me.Text1, Me.List1.hWnd)
End Sub
Private Sub Form_Load()
With List1
.AddItem "ma"
.AddItem "nong"
.AddItem "ku"
.AddItem ".com"
.AddItem "mang"
.AddItem "guo"
.AddItem "ke"
.AddItem "yi"
End With
End Sub
在Text1中输入mang可以看到结果。