大家经常都会用到这样一个问题。当用户往一个TextBox(MultiLine = False)输入数据或文字时,自动在其下下方(或上方)弹出一个下拉框,下拉框中列出用户以前在此输入的一些数字(或文字串)。
如:我们经常去Google搜索,当我们准备在搜索框里面键入我们要搜索的东西的时候,其下方都会弹出一个下拉框,里面列出我们以前在此搜索过的东西。这种下拉框和普通的ComboBox是不同的:
1.它没有下拉按钮
2.它的下拉列表的右下角会有一个小三角形,用鼠标拖动它可以更改下拉框的大小注:如果各位喜欢分的话,我可以多开几个帖子,分我有得是。
谢谢!哦,忘记说问题了,问题就是这个控件在哪个ocx里面,谢谢!

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/3558/3558756.xml?temp=.4649317要分者请进!
      

  2.   

    发错了,不好意思,是下面这个http://community.csdn.net/Expert/topic/3558/3558747.xml?temp=.8506128要分者请进!
      

  3.   

    注:我只要这个ocx,关于如何自动下拉,如何更改下拉列表的宽度,我都知道,只是不想费事去自己做一个控件。
    谢谢!
      

  4.   

    多加个LIstbox而已有那么麻烦吗?
      

  5.   

    form中加1个text,1个list,写的很粗略,你再改改
    Option ExplicitDim bool As Boolean   '是否change了Private Sub Form_Load()
        bool = True
    End SubPrivate Sub List1_Click()
        Text1.Text = List1.Text
        Text1.SelStart = Len(Text1.Text)
        List1.Visible = False
        
    End SubPrivate Sub Text1_Change()
        If bool = True Then
            List1.Visible = True
            List1.Clear
            Dim i As Integer
            For i = 1 To 5
                List1.AddItem Text1.Text & i
            Next
            bool = False
        Else
            bool = True
        End If
    End Sub
      

  6.   

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const CB_SHOWDROPDOWN = &H14F
    Private Const WM_SETREDRAW As Long = &HB&
    Private Const CB_FINDSTRING As Long = &H14C&'iKeyCode目的:传递KeyDown事件中的KeyCode
    Private iKeyCode As IntegerPublic Sub SearchCombo(InControl As Object)
        On Error GoTo errTrap
         
        Dim StrPos As Long
        Dim lPos As Long
        Dim SearchStr As String
         
        If TypeOf InControl Is ComboBox Then
            StrPos = InControl.SelStart
            SearchStr = Left$(InControl.Text, StrPos)
            
            lPos = SendMessage(InControl.hwnd, CB_FINDSTRING, 0, ByVal SearchStr)
            
            If lPos >= 0 Then
                InControl.Text = InControl.List(lPos)
                InControl.ListIndex = lPos
            End If
            
            With InControl
                .SelStart = StrPos
                .SelLength = Len(InControl.Text)
            End With
        End If
        Exit Sub
    errTrap:
         MsgBox Err.Description
    End Sub
     Private Sub Combo1_Change()
        If iKeyCode <> vbKeyBack And iKeyCode <> vbKeyReturn Then
            SearchCombo Combo1
            SendMessageLong Combo1.hwnd, CB_SHOWDROPDOWN, True, 0
        End If
    End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
        iKeyCode = KeyCode
    End SubPrivate Sub Form_Load()
        Combo1.AddItem "asqwed"
        Combo1.AddItem "fgtthgh"
        Combo1.AddItem "nfgftrtyr"
        Combo1.AddItem "werwerwe"
        Combo1.AddItem "ytrtyrtyrty"
        Combo1.AddItem "bfrthrtyrt"
        Combo1.AddItem "rewerwe"
        Combo1.AddItem "vsfsdf"
    End Sub
      

  7.   

    Thank you lxcc(虫子|专注于抢分) 。这两个功能我早就知道怎么做,但还是非常谢谢你的参与。
    我的问题在前面已经讲得很清楚了,请您看清楚,谢谢!
      

  8.   

    aiur2000(开始.NET) ,谢谢你!这确实是一种简单可行的方法,但是如果要再实现ListBox右下角的小三角形的功能可能就又有一点麻烦了。
      

  9.   

    Option ExplicitPublic Enum SHAutoCompleteFlags
       ' // Currently (SHACF_FILESYSTEM | SHACF_URLALL)
       SHACF_DEFAULT = &H0
       ' // This includes the File System as well as the rest of the shell 
       ' (Desktop\My Computer\Control Panel\)
       SHACF_FILESYSTEM = &H1
       ' // URLs in the User's History
       SHACF_URLHISTORY = &H2
       ' // URLs in the User's Recently Used list.
       SHACF_URLMRU = &H4
       ' // Use the tab to move thru the autocomplete possibilities 
       ' instead of to the next dialog/window control.
       SHACF_USETAB = &H8
       SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)
       ' // This includes the File System 
       SHACF_FILESYS_ONLY = &H10                     '#if (_WIN32_IE >= = &H0600)
       ' // Same as SHACF_FILESYS_ONLY except it only includes directories, 
       ' UNC servers, and UNC server shares. 
       SHACF_FILESYS_DIRS = &H20                     
    '#End If ' // (_WIN32_IE >= = &H0600)
       
       ' // Ignore the registry default and force the feature on.
       SHACF_AUTOSUGGEST_FORCE_ON = &H10000000
       ' // Ignore the registry default and force the feature off.
       SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000
       ' // Ignore the registry default and force the feature on. 
       ' (Also know as AutoComplete)
       SHACF_AUTOAPPEND_FORCE_ON = &H40000000
        ' // Ignore the registry default and force the feature off. 
        ' (Also know as AutoComplete)
       SHACF_AUTOAPPEND_FORCE_OFF = &H80000000
    End EnumPrivate Declare Function SHAutoComplete Lib "shlwapi.dll" ( _
       ByVal hwndEdit As Long, ByVal dwFlags As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
       (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, _
       ByVal lpszWindow As String) As LongPrivate Const S_OK = 0Public Function AutoComplete( _
          ByVal hWnd As Long, _
          ByVal eFlags As SHAutoCompleteFlags _
       )
    Dim lR As Long
       lR = SHAutoComplete(hWnd, eFlags)
       AutoComplete = (lR <> S_OK)
    End Function
    Public Function GetComboBoxEdithWnd(ByVal hWnd As Long) As Long
       GetComboBoxEdithWnd = FindWindowEx(hWnd, 0, "EDIT", vbNullString)
    End Function'To test the function, add a TextBox and a ComboBox to the Project's form. Name the TextBox "txtTest" and the ComboBox "cboTest". Then add this code to the project's form:Private Sub Form_Load()
       AutoComplete txtTest.hWnd, SHACF_FILESYS_ONLY
       AutoComplete GetComboBoxEdithWnd(cboTest.hWnd), SHACF_FILESYS_ONLY
    End Sub在文本框内输入c:\ 然后就可以看到效果!
      

  10.   

    Thank you very much!!!
    这样吧,虫子,鉴于你的贡献之大,我再给你开两个帖(200分),以表达我对你的谢意,OK?
    Thank you!
      

  11.   

    http://community.csdn.net/Expert/topic/3558/3558747.xml?temp=.5977747
    http://community.csdn.net/Expert/topic/3563/3563685.xml?temp=.7456171来这两个帖报到吧,专为你送分的,呵呵
      

  12.   

    这样吧,虫子,鉴于你的贡献之大,我再给你开两个帖(200分),以表达我对你的谢意,OK?
    //我肯定木有问题 :D
      

  13.   

    http://community.csdn.net/Expert/topic/3563/3563685.xml?temp=.7456171
    http://community.csdn.net/Expert/topic/3563/3563680.xml?temp=.8227655
    Sorry,错了,是这两个