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 |
Related posts:
- How to Make a ComboBox’s dropdown area wide enough for its choices, allowing for ScaleMode
- How to Make a ComboBox’s dropdown area wide enough for its choices
- How to set the ComboBox DropDown List Width
- How to set the ComboBox DropDown List Height
- How to add CheckBox to ComboBox
- How to show the Drop Down of ComboBox List
- How to get the Width of the String
- How to generate list in combobox with all dates of current month
- How to Draw 3D Gradient text on form
- How to add Horizonal Scroll Bar to ListBox
Enjoy this article?
Filed under: Controls
Leave a comment
Sponsors
Link Back to us
Donations
If you are benefited from this site, please donate a small contribution to us. It will help to maintain this site better.