Results 1 to 3 of 3

Thread: VB Snippet - Resizing a ComboBox's Drop Down Height

Threaded View

  1. #1

    Thread Starter
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596

    VB Snippet - Resizing a ComboBox's Drop Down Height

    This code is really useful!
    VB Code:
    1. Private Type RECT
    2.    Left As Long
    3.    Top As Long
    4.    Right As Long
    5.    Bottom As Long
    6. End Type
    7.  
    8. Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    9. Private Declare Function ScreenToClientAny Lib "user32" Alias "ScreenToClient" (ByVal hWnd As Long, lpPoint As Any) As Long
    10. 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
    11.  
    12. Public Sub SetComboBoxHeight(ComboBox As ComboBox, ByVal NewHeight As Long)
    13. Dim lpRect As RECT
    14. Dim wi As Long
    15. GetWindowRect CB.hWnd, lpRect
    16. wi = lpRect.Right - lpRect.Left
    17. ScreenToClientAny CB.Parent.hWnd, lpRect
    18. MoveWindow CB.hWnd, lpRect.Left, lpRect.Top, wi, NewHeight, True
    19. End Sub
    You can use it in this manner:
    VB Code:
    1. Private Sub Form_Load()
    2. SetHeightComboBox Combo1, 200
    3. 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!
    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.
    Last edited by seec77; Mar 2nd, 2003 at 05:37 AM.
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width