请问,当组合框无列表选项时,怎么改变空列表的长度,VC中是很简单,不知道VB怎么做?

解决方案 »

  1.   

    Option ExplicitPrivate Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, lpRect As RECT) As Long
    Private Const SWP_NOZORDER = &H4
    Private Const SWP_SHOWWINDOW = &H40
    Private Const SWP_FRAMECHANGED = &H20
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOACTIVATE = &H10Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
    Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
            (ByVal hWnd As Long, ByVal wmsg As Long, ByVal wparam As Long, lParam As Long) As Long
    Const CB_SETDROPPEDWIDTH = &H160'  设置ComboBox下拉选单长度函数
    Public Sub setcomboheight(combobox_obj As ComboBox, ByVal newheight As Long)
        
        Dim mscale As Single
        Dim RT As RECT
        GetWindowRect combobox_obj.hWnd, RT
        SetWindowPos combobox_obj.hWnd, 1, 0, 0, RT.Right - RT.Left, newheight, SWP_NOMOVE Or SWP_NOZORDER
    End Sub'  设置ComboBox下拉选单宽度函数
    Public Sub SetComboWidth(combobox_obj As ComboBox, ByVal NewWidth As Long)
        '  NewWidth 是宽度,单位是 pixels
        SendMessage combobox_obj.hWnd, CB_SETDROPPEDWIDTH, NewWidth, ByVal 0&
    End SubPrivate Sub Command1_Click()
        Call setcomboheight(Combo1, 300)       '设置长度
        Call SetComboWidth(Combo1, 200)         '设宽度
    End Sub