Увеличить ширину выпадающего списка ComboBox - VB
Формулировка задачи:
Подскажите. Можно ли как то "растянуть" ComboBox. Что бы выпадающий список стал шире по размеру.Может как то задать этот размер или определить через длину самого длинного значения в нем. Вот, для наглядности кидаю скрин:
Решение задачи: «Увеличить ширину выпадающего списка ComboBox»
textual
Листинг программы
Private Type RECT iLeft As Long iTop As Long iRight As Long iBottom As Long End Type Private Type COMBOBOXINFO cbSize As Long rcItem As RECT rcButton As RECT stateButton As Long hwndCombo As Long hwndItem As Long hwndList As Long End Type Private Type Size cx As Long cy As Long End Type Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function GetTextExtentPoint Lib "gdi32" Alias "GetTextExtentPointW" (ByVal hdc As Long, ByVal lpszString As Long, ByVal cbString As Long, lpSize As Size) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Const CB_GETCOMBOBOXINFO = &H164 Private Const CB_SETDROPPEDWIDTH = &H160 Private Const LB_GETTEXT = &H189 Private Const LB_GETTEXTLEN = &H18A Private Const WM_GETFONT = &H31 Private Sub Form_Load() Combo1.AddItem "ÏîäñêГ*æèòå. ÌîæГ*Г® ëè ГЄГ*ГЄ ГІГ® Г°Г*Г±ГІГїГ*ГіГІГј ComboBox. Г—ГІГ® ГЎГ» âûïГ*Г¤Г*ГѕГ№ГЁГ© ñïèñîê Г±ГІГ*Г« øèðå ГЇГ® Г°Г*çìåðó." Combo1.AddItem "Ìîæåò ГЄГ*ГЄ ГІГ® Г§Г*Г¤Г*ГІГј ýòîò Г°Г*çìåð èëè îïðåäåëèòü ÷åðåç äëèГ*Гі Г±Г*ìîãî äëèГ*Г*îãî Г§Г*Г*Г·ГҐГ*ГЁГї Гў Г*ГҐГ¬." Combo1.AddItem "Âîò, äëÿ Г*Г*ãëÿäГ*îñòè ГЄГЁГ¤Г*Гѕ ñêðèГ*:" Dim inf As COMBOBOXINFO Dim i As Long Dim sz As Size Dim max As Long Dim dc As Long Dim buf As String Dim c As Long Dim fnt As Long Dim oft As Long inf.cbSize = Len(inf) SendMessage Combo1.hwnd, CB_GETCOMBOBOXINFO, 0, inf dc = GetDC(inf.hwndList) fnt = SendMessage(inf.hwndList, WM_GETFONT, 0, ByVal 0&) ofnt = SelectObject(dc, fnt) For i = 0 To Combo1.ListCount - 1 c = SendMessage(inf.hwndList, LB_GETTEXTLEN, i, ByVal 0&) buf = Space(c) SendMessage inf.hwndList, LB_GETTEXT, i, ByVal buf GetTextExtentPoint dc, StrPtr(buf), c, sz If sz.cx > max Then max = sz.cx Next SelectObject dc, ofnt ReleaseDC inf.hwndList, hwnd SendMessage Combo1.hwnd, CB_SETDROPPEDWIDTH, max + 8, ByVal 0& End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д