Home » Controls » How to expand the width of a combobox to the width of the listed items
How to expand the width of a combobox to the width of the listed items
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 'Controls - How to expand the width of a combobox to the width of the listed items Option Explicit Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const CB_SETDROPPEDWIDTH = &H160 Public Sub ComboWidthAdjustment(Cmb As ComboBox) Dim I As Long Dim max_wid As Long Dim cur_wid As Long Dim SaveMode As Long Dim Fnt As StdFont With Cmb SaveMode = .Parent.ScaleMode Set Fnt = .Parent.Font .Parent.ScaleMode = vbPixels Set .Parent.Font = .Font For I = 0 To .ListCount - 1 cur_wid = .Parent.TextWidth(.List(I)) If max_wid < cur_wid Then max_wid = cur_wid Next I SendMessage .hWnd, CB_SETDROPPEDWIDTH, max_wid + 10, 0 .Parent.ScaleMode = SaveMode Set .Parent.Font = Fnt End With End Sub |
Enjoy this article?
Filed under: Controls
Leave a comment