Auto Complete combo Box(VB.NET Source Use API)
2024-07-10 13:02:36
供稿:网友
本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。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