Auto Complete combo Box(VB.NET Source Use API)
2008-04-24 12:52
316 查看
Private Declare Function LockWindowUpdate Lib "User32" (ByVal hWndLock As System.IntPtr) As Long
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
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
相关文章推荐
- Auto Complete combo Box(VB.NET Source Use API)
- Auto Complete combo Box(VB.NET Source Use API)
- Three ways to use C# within a VB.NET project
- 字符串加解密的类(VB.NET Source Code)
- 关于vb.net里面api Unicode/ANSI调用一个问题解答
- [VB.NET].net平台调用API问题
- 实现用C#和VB.NET调用Ghostscript的API,把Postscript文件转为PDF文件。
- vb.net 调用api
- PDA Battery Info (VB.Net+.Net CF) Source Code
- 用vb.net读取INI配置文件的方法,使用API
- VB.net 连接 MySql,Use MySql.Data.dll
- 【转】[C#.NET][VB.NET] 用 Win32 API 控制 外部應用程式選單
- VB.net对于datagride控件的使用及C#中datagrideView\bindingSource\bindingNavigator\tabcontrol控件的应用
- [VB.NET]有人用过API CreateFileMapping 内存共享 没有?能后给段例子?
- VB.NET及C#调用API
- The UDPChat Source(VB.NET)
- 一个基于API的VB.net串口通讯类
- VB.net 注册表操作API
- 游戏手柄编程DEMO 基于 VB.NET+API 暂无力反馈
- 面向Google、YouTube、Facebook以及其他Web 2.0 API的C#和VB.NET类库