Auto Complete combo Box(VB.NET Source Use API)

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 blood 的 blog

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

本文关键:Combo
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top