Private Sub Form_Load()
Combo1.Clear
Combo1.AddItem "MyControlName"
End Sub

解决方案 »

  1.   

    Private Sub Combo1_DropDown()
      '显示自已的控件
      '自己的控件.SetFocus
    End Sub
      

  2.   

    你试过了吗?
    Private Sub Combo1_DropDown()
      '显示自已的控件
      '自己的控件.SetFocus
    End Sub
      

  3.   

    : Bardo(巴顿) 剩下的都被你吃了吧,:)
      

  4.   

    aproc 是否何问的?
    你们答的又是什么? 
    如果真是这么初级,我想aproc肯定不会问!
    所以,我决不会这样回答这类问题。
    因为这样不仅是对别人的不尊重。(你们将自己看得太高,将别人看得太低)
    实际是给自己画像。
    以下是什么代码?VB 幼儿园的代码!!!!!!!!!!!!
    Private Sub Combo1_DropDown()
      '显示自已的控件
      '自己的控件.SetFocus
    End Sub
      

  5.   

    Private Sub Combo1_DropDown()
       Frame1.Visible = False
       Frame1.SetFocus
       '注: 这是世纪国际著名VB 大师的手笔
    End Sub
      

  6.   

    我还没有找到真正的方法,
    但下面的代码一定可以提供一个思路:'In a Module..
    private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (byval hwnd as Long, byval nIndex as Long, byval dwNewLong as Long) as Longprivate Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (byval lpPrevWndFunc as Long, byval hwnd as Long, byval Msg as Long, byval wParam as Long, byval lParam as Long) as Longprivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Any) as Longprivate Const GWL_WNDPROC = (-4)private Const WM_CTLCOLORLISTBOX = &H134private Const LB_GETCURSEL = &H188private lPrevWndFunc as Longpublic oLabel as Labelprivate Function WindowProc(byval hwnd as Long, byval Msg as Long, byval wParam as Long, byval lParam as Long) as Long    Dim iIndex as Long          If Msg = WM_CTLCOLORLISTBOX then                iIndex = SendMessage(lParam, LB_GETCURSEL, 0&, byval 0&)        If iIndex >= 0 then oLabel = "Item Index: " & iIndex  
      End If    WindowProc = CallWindowProc(lPrevWndFunc, hwnd, Msg, wParam, lParam)End Functionpublic Sub SubClassIt(byval hwnd as Long, byval Add as Boolean)   
     If Add then        
          lPrevWndFunc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)    
     else        
          Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWndFunc)   
     End IfEnd SubIn a Form, with a Label and a ComboBox..private Sub Form_Load()    Dim iIndex as Long    
    set oLabel = Label1    
    SubClassIt Combo1.hwnd, true    for iIndex = 1 to 10        
    Combo1.AddItem "Item " & iIndex    
    nextEnd Subprivate Sub Form_Unload(Cancel as Integer)    SubClassIt Combo1.hwnd, falseEnd Sub
      

  7.   

    晕!又一个简单问题复杂化
    我放一个textbox再放一个小的commandbutton,button上放个图,伪装成combox
    不就可以了吗?
      

  8.   

    回复人: fuxc(Michael) (2001-12-28 23:41:22)  得0分 
    晕!又一个简单问题复杂化
    我放一个textbox再放一个小的commandbutton,button上放个图,伪装成combox
    不就可以了吗?  
    回复人: calligraphy(小九) (2001-12-29 0:09:14)  得0分 
    : fuxc(Michael) 说的对  又一个简单问题复杂化:抽水马桶说的对:还是用茅坑  
      

  9.   

    回复人: fuxc(Michael) (2001-12-28 23:41:22)  得0分 
    晕!又一个简单问题复杂化
    我放一个textbox再放一个小的commandbutton,button上放个图,伪装成combox
    不就可以了吗?  
    回复人: calligraphy(小九) (2001-12-29 0:09:14)  得0分 
    : fuxc(Michael) 说的对  又一个简单问题复杂化:抽水马桶说的对:还是用茅坑骑马最好,要用什么骄车?同样,自来水,煤气灶。全不要
      
      

  10.   

    为什么要用微积分简单的算术即可所以我想 CSDN应当 
    分一下级别
    初级与高级一起讨论
    就象与小学生讨论微积分
      

  11.   

    嗬嗬,巴顿你的脾气太火爆了,不过你说得也对,
    明明用两个简单控件可以解决的问题,非得写上n行代码,还要调api,
    不是放着小轿车不坐,非要骑马吗?
      

  12.   

    有没有这么复杂啊!
    就用text,commad。 和 list 的组合不行吗?
    text_dbclick 时tree_setfocus
    command_click 时tree_setfocus
    list1_mouseup 时
                  list.visble=flase
                 text.text=tree.Selectitem.text
                 text.setfocus
    tree_lostfocus 时
                 list.visble=flase
                 text.text=tree.Selectitem.text
                 text.setfocus
    我个人认为是可行的Private Sub Command2_Click()
      List1.Visible = Not List1.Visible
      If List1.Visible Then
             List1.SetFocus
             List1.ListIndex = 0
      Else
             Text1.Text = List1.List(List1.ListIndex)
       End If
    End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       If List1.Visible Then List1_LostFocus
    End SubPrivate Sub List1_LostFocus()
       List1.Visible = False
       Text1.SetFocus
       Text1.Text = List1.List(List1.ListIndex)
    End SubPrivate Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
      List1_LostFocus
    End SubPrivate Sub Text1_DblClick()
      List1.Visible = True
      List1.SetFocus
      List1.ListIndex = 0
    End Sub
      

  13.   

    不和你们争了。
    你那种不可能封装为控件。答案请去:http://vbaccelerator.com/codelib/ddtoolwn/ddform.htm
      

  14.   

    还没有找到真正的办法,在这儿说这么多干吗呀!?!?!?!?!说不回答这种问题又要讲哪么多?aproc 是如何问的,有没有看清啊?aproc 都没提出批评意见,操哪么多心干吗?!?!?还没有几个人这么露骨的说自己是"高级的"!!,VB是不是也是你自已写的啊!!!见个大鬼.闪!!!!
      

  15.   

    fram1.setfocusRun time error!!
      

  16.   

    出自高手的极品代码......
    Private Sub Combo1_DropDown()
      Frame1.Visible = False
      Frame1.SetFocus
      '注: 这是世纪国际著名VB 大师的手笔
    End Subhehe...............
      

  17.   

    回复人: Bardo(巴顿) (2001-12-30 20:44:28)  得0分 
    fram1.setfocusRun time error!!  On Error Resumme Next^_^
      

  18.   

    还是给出代码吧!!!'In a module
    =====
    Option Explicit
    Public defWinProc As LongPublic Const GWL_WNDPROC As Long = -4
    Private Const CBN_DROPDOWN As Long = 7
    Private Const WM_LBUTTONDOWN As Long = &H201
    Private Const WM_KEYDOWN As Long = &H100
    Private Const VK_F4 As Long = &H73Private Declare Function CallWindowProc _
    Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, _
    ByVal hwnd As Long, ByVal Msg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As LongPublic Declare Function SetWindowLong _
    Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
    Public Sub Unhook(hwnd As Long)If defWinProc <> 0 ThenCall SetWindowLong(hwnd, _
    GWL_WNDPROC, _
    defWinProc)
    defWinProc = 0
    End IfEnd Sub
    Public Sub Hook(hwnd As Long)'Don't hook twice or you will
    'be unable to unhook it.
    If defWinProc = 0 ThendefWinProc = SetWindowLong(hwnd, _
    GWL_WNDPROC, _
    AddressOf WindowProc)End IfEnd Sub
    Public Function WindowProc(ByVal hwnd As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long'only if the window is the combo box...
    If hwnd = Form1.Combo1.hwnd ThenSelect Case uMsgCase CBN_DROPDOWN 'the list box of a combo
    'box is about to be made visible.'return 1 to indicate we ate the message
    WindowProc = 1Case WM_KEYDOWN 'prevent the F4 key from showing
    'the combo's listIf wParam = VK_F4 Then'set up the parameters as though a
    'mouse click occurred on the combo,
    'and call this routine again
    Call WindowProc(hwnd, WM_LBUTTONDOWN, 1, 1000)Else'there's nothing to do keyboard-wise
    'with the combo, so return 1 to
    'indicate we ate the message
    WindowProc = 1End IfCase WM_LBUTTONDOWN 'process mouse clicks'if the listview is hidden, position and show it
    If Form1.ListView1.Visible = False ThenWith Form1
    .ListView1.Left = .Combo1.Left
    .ListView1.Width = .Combo1.Width
    .ListView1.Top = .Combo1.Top + .Combo1.Height + 1
    .ListView1.Visible = True
    .ListView1.SetFocus
    End WithElse'the listview must be visible, so hide it
    Form1.ListView1.Visible = False
    End If'return 1 to indicate we processed the message
    WindowProc = 1Case Else'call the default window handler
    WindowProc = CallWindowProc(defWinProc, _
    hwnd, _
    uMsg, _
    wParam, _
    lParam)End SelectEnd If 'If hwnd = Form1.Combo1.hwndEnd Function===='In a form, add a combo box, a listview and three command buttons=====
    Option ExplicitPrivate bKeepOpen As BooleanPrivate Sub Form_Load()Dim c As Long
    Dim chd As ColumnHeader
    Dim itmx As ListItem'Add some dummy data to the listview and hide
    With ListView1Set chd = .ColumnHeaders.Add(, , "Name", 1000)
    Set chd = .ColumnHeaders.Add(, , "Col 2", 1000)
    Set chd = .ColumnHeaders.Add(, , "Col 3", 1000)
    Set chd = .ColumnHeaders.Add(, , "Col 4", 600)For c = 1 To 15
    Set itmx = .ListItems.Add(, , Screen.Fonts(c))
    itmx.SubItems(1) = "screen"
    itmx.SubItems(2) = "font"
    itmx.SubItems(3) = c
    Next.View = lvwReport
    .FullRowSelect = True 'vb6 only
    .BorderStyle = ccNone
    .Visible = FalseEnd With'set inital state of command buttons
    Command1.Caption = "hook combo"
    Command2.Caption = "unhook combo"
    Command3.Caption = "unhook && end"
    Command1.Enabled = True
    Command2.Enabled = False
    End Sub
    Private Sub Command1_Click()If defWinProc = 0 Then
    Hook Combo1.hwnd
    Command1.Enabled = False
    Command2.Enabled = True
    End IfEnd Sub
    Private Sub Command2_Click()'unhook the combo
    If defWinProc <> 0 Then
    Unhook Combo1.hwnd
    defWinProc = 0
    Command1.Enabled = True
    Command2.Enabled = False
    End IfEnd Sub
    Private Sub Command3_Click()Unload MeEnd Sub
    Private Sub Form_Unload(Cancel As Integer)If defWinProc <> 0 Then Unhook Combo1.hwndEnd Sub
    Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)'set flag to allow arrow and enter
    'keys to simulate behaviour of normal
    'combo
    bKeepOpen = TrueEnd Sub
    Private Sub List1_KeyPress(KeyAscii As Integer)'set flag to allow arrow and enter
    'keys to simulate behaviour of normal
    'combo
    If KeyAscii = vbKeyReturn Then'simulate selecting item with enter
    bKeepOpen = False
    Call ListView1_Click
    Else'alpha or arrow keys being used,
    'so keep open
    bKeepOpen = TrueEnd IfEnd Sub
    Private Sub ListView1_Click()Dim itmx As ListItemIf ListView1.ListItems.Count > 0 ThenSet itmx = ListView1.SelectedItem'For a style 0 combo, you can not assign
    'to the Text property from within the click
    'event, so the selected item must be 'added'
    'as the only combo item, and selected using
    'its listindex property.
    '
    'For a style 2 combo, the text property
    'can't be set unless there is an exact
    'match to a list item, so again we fake it
    'by adding the selection to the combo and
    'selecting it.
    '
    'Finally, since the tabs can't be used
    'in the combo's edit window, as it doesn't
    'support tabstops either, on selection we'll
    'display the main listview item
    With Combo1
    .Clear
    .AddItem itmx.Text
    .ListIndex = 0
    End WithEnd IfIf bKeepOpen = False Then
    ListView1.Visible = False
    Combo1.SetFocus
    End IfEnd Sub
    =====
      

  19.   

    没想到这个问题引来了这么多的讨论,我以为没有结果,所以好久没有来看。先谢谢大家!
    我是想自己做个控件。其中包括一个combox,还有好多checkbox.操作时点击combox,出现那些checkbox,点选其中的一部分,确认,将选中的结果显示在combox上。准备用来处理一个人会几种外语之类的问题。
    我没有仔细看Bardon的答案,不过还是把分给他。感谢他的热情。也谢谢其它人。