Auto Complete combo Box(VB.NET Source Use API)
点击次数:66 次 发布日期:2008-11-06 08:07:00 作者:源代码网
|
源代码网推荐 Private Structure SIZE 源代码网推荐 Dim cx As Long 源代码网推荐 Dim cy As Long 源代码网推荐 End Structure 源代码网推荐 Public Sub LockWindow(ByVal hwnd As System.IntPtr) 源代码网推荐 Dim lRet As Long 源代码网推荐 lRet = LockWindowUpdate(hwnd) 源代码网推荐 End Sub 源代码网推荐 Private Sub ReleaseWindow() 源代码网推荐 Dim lRet As Long 源代码网推荐 lRet = LockWindowUpdate(Nothing) 源代码网推荐 End Sub 源代码网推荐 Private Sub ComboDropdown(ByRef comboObj As ComboBox) 源代码网推荐 Call SendMessage(comboObj.Handle, CB_SHOWDROPDOWN, 1, 0&) 源代码网推荐 End Sub 源代码网推荐 Private Sub ComboRetract(ByRef comboObj As ComboBox) 源代码网推荐 Call SendMessage(comboObj.Handle, CB_SHOWDROPDOWN, 0, 0&) 源代码网推荐 End Sub 源代码网推荐 Public Function ComboAutoComplete(ByRef comboObj As ComboBox) As Boolean 源代码网推荐 Dim lngItemNum As Long 源代码网推荐 Dim lngSelectedLength As Long 源代码网推荐 Dim lngMatchLength As Long 源代码网推荐 Dim strCurrentText As String 源代码网推荐 Dim strSearchText As string 源代码网推荐 Dim sTypedText As String Const CB_LOCKED = &H255 源代码网推荐 Try 源代码网推荐 With (comboObj) 源代码网推荐 If .Text = Nothing Then 源代码网推荐 Exit Function 源代码网推荐 End If 源代码网推荐 Call LockWindow(.Handle) 源代码网推荐 If ((InStr(1, .Text, .Tag, vbTextCompare) <> 0 And Len(.Tag) = Len(.Text) - 1) Or (Left(.Text, 1) <> Left(.Tag, 1) And .Tag <> Nothing)) And .Tag <> CStr(CB_LOCKED) Then 源代码网推荐 strSearchText = .Text 源代码网推荐 lngSelectedLength = Len(strSearchText) 源代码网推荐 lngItemNum = .FindString(strSearchText) 源代码网推荐 ComboAutoComplete = Not (lngItemNum = -1) 源代码网推荐 If ComboAutoComplete Then 源代码网推荐 lngMatchLength = Len(.Items.Item(lngItemNum)) - lngSelectedLength .Tag = CB_LOCKED 源代码网推荐 sTypedText = strSearchText 源代码网推荐 .Text = .Text & Right(.Items.Item(lngItemNum), lngMatchLength) 源代码网推荐 .SelectionStart = lngSelectedLength 源代码网推荐 Dim Temp As Integer Temp = lngMatchLength .SelectionLength = Temp 源代码网推荐 ".Text = .Text & Right(.Items.Item(lngItemNum), lngMatchLength) .Tag = sTypedText 源代码网推荐 End If 源代码网推荐 ElseIf .Tag <> CStr(CB_LOCKED) Then 源代码网推荐 .Tag = .Text 源代码网推荐 End If 源代码网推荐 Call ReleaseWindow() 源代码网推荐 End With 源代码网推荐 Catch err As Exception 源代码网推荐 MsgBox(err.Message & err.StackTrace) 源代码网推荐 End Try 源代码网推荐 End Function 源代码网推荐 源代码网供稿. |
