Library code snippets

Set the Combo Drop height and width

You can set the drop down height and width by sending a message, and using the MoveWindow Windows API function. Use the following code to set its height and width:

' Declare functions
' Move Window is for SetDropHeight
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

' SendMessage is for Set Drop Width
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
' Constant for SetDropWidth
Private Const CB_SETDROPPEDWIDTH = &H160

' SetDropWidth
Private Sub SetDropWidth(lngWidth As Long)
    Dim lRet As Long
    lRet = SendMessageLong(Combo1.hwnd, CB_SETDROPPEDWIDTH, lngWidth, 0)
End Sub

' SetDropHeight
Private Sub SetDropHeight(lngHeight As Long)
    Dim lRet As Long
    Dim iScaleMode As Integer
    iScaleMode = Combo1.Parent.ScaleMode
    Combo1.Parent.ScaleMode = vbPixels
    lRet = MoveWindow(Combo1.hwnd, Combo1.Left, Combo1.Top, Combo1.Width, lngHeight, 1)
    Combo1.Parent.ScaleMode = iScaleMode
End Sub

Comments

  1. 03 Aug 2006 at 00:18

    I have a tab on it a  frame and on this several comboboxes.

    How do I change the code so I can manipulate the height of each combobox?

    The code works with only combo1.

    '************************************************************************
    Private Sub Form_Load()
    Dim i%
     
      For i = 1 To 10
        Combo1.AddItem "This is the entry number " & Trim$(i)
      Next
      Option1(0) = 1






    ' SubClass ComboBox.hwnd, BOOL, Width, Height, Alignment
    ' Width and Height values in Pixel
    ' Alignment: 0 = left, 1 = right, 2 = centered
     
      'SubClass Combo1.hwnd, True, 145, 0, 0   '# don't change height
      SubClass Combo1.hwnd, True, 145, -1, 0   '# adapt height to the entry number
      'SubClass Combo1.hwnd, True, 145, 200, 0 '# change height
    End Sub






    '************************************************************************
    Private Sub Form_Unload(Cancel As Integer)
      '# Optional, but recommended
      SubClass Combo1.hwnd, False
    End Sub



    '************************************************************************
    '# for demo purposes
    Private Sub Option1_Click(Index As Integer)
      Call SetAlignment(Index)
    End Sub



    '************************************************************************

     

     

  2. 27 Aug 2003 at 10:50

    Thanks a lot!

  3. 26 Aug 2003 at 19:00

    if anyone interested found a much better solution...    


    on following the following site...



    http://artima1.inetu.net/pipermail/software-keyholes/2003-July/000063.html


  4. 22 Aug 2003 at 13:59

    If you are looking 4 the answer to your question how to change drop down height in a frame then follow the link below... And download vb example... Works in a frame and in on tabs...


    A complete site for windows API Calls...


    Combo API Example
    http://www.mentalis.org/vbexamples/vbexample.php?vbexample=COMBO&category=SOURCE


     

  5. 02 Jul 2003 at 14:46

    If the combo box belongs to some frame control, how to change the height?

  6. 01 Jan 1999 at 00:00

    This thread is for discussions of Set the Combo Drop height and width.

Leave a comment

Sign in or Join us (it's free).