|
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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As
Long
Const CB_GETITEMHEIGHT = &H154
Private Sub Form_Load()
Dim i As Integer
'Заполняем комбобокс значениями
For i = 1 To 50
Combo1.AddItem Format$(i)
Next i
Combo1.ListIndex = 0
'Меняем размер выпадающей части комбобокса
ReSizeCombo Me, Combo1, 9
End Sub
Public Sub ReSizeCombo(frm As Form, cbo As ComboBox, n As Integer)
'Процедура меняет размер выпадающей части
комбобокса
Dim cboLeft As Long
Dim cboTop As Long
Dim cboWidth As Long
Dim cboHeight As Long
Dim oldScaleMode As Long
Dim h As Long
'Меняем Scale Mode формы на пиксели.
oldScaleMode = frm.ScaleMode
frm.ScaleMode = vbPixels
'Сохраняем размеры комбобокса
cboLeft = cbo.Left
cboTop = cbo.Top
cboWidth = cbo.Width
'Получаем высоту одной строчки в пикселях
h = SendMessage(cbo.hwnd, CB_GETITEMHEIGHT, 0, 0)
'Задаем новую высоту комбобокса
'К количеству строк надо прибавить 2 (не знаю
почему)
cboHeight = h * (n + 2)
frm.ScaleMode = oldScaleMode
'и собственно ресайзаем
MoveWindow cbo.hwnd, cboLeft, cboTop, cboWidth, cboHeight, 1
End Sub
|
|