This code is really useful!
You can use it in this manner:VB Code:
Private 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 Declare Function ScreenToClientAny Lib "user32" Alias "ScreenToClient" (ByVal hWnd As Long, lpPoint As Any) As Long 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 Public Sub SetComboBoxHeight(ComboBox As ComboBox, ByVal NewHeight As Long) Dim lpRect As RECT Dim wi As Long GetWindowRect CB.hWnd, lpRect wi = lpRect.Right - lpRect.Left ScreenToClientAny CB.Parent.hWnd, lpRect MoveWindow CB.hWnd, lpRect.Left, lpRect.Top, wi, NewHeight, True End Sub
If you set the NewHeight to something larger than all the entries in the ComboBox the height of the DropDown is the sum of all the entries!VB Code:
Private Sub Form_Load() SetHeightComboBox Combo1, 200 End Sub
BTW, the NewHeight is in pixels...
I got this code from VB2theMax, and I do not take any credit for the code. I just thought people might like this code and I couldn't find any similar code in the Code Bank.






Reply With Quote