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

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov