Public 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 LongMoveWindow combobox1.hwnd, combobox1.Left, combobox1.Top, combobox1.width, combobox1.height*2, 1
Private Sub Form_Load()
MoveWindow Combo1.hwnd, 100, 100, 100, Combo1.Height * 2, 1
End Sub
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As LongPublic Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As LongPublic Declare Function ScreenToClient Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINTAPI) As LongPublic 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 LongPublic Const CB_GETITEMHEIGHT = &H154Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePublic Type POINTAPI
x As Long
y As Long
End Type然后在combobox的form中加一个sub
Sub SetComboBoxHeight()
Dim Point As POINTAPI
Dim Rectangle As RECT
Dim ComboBoxWidth As Long
Dim NewComboBoxHeight As Long
Dim EditAreaHeight As Long
Dim OldScaleMode As Long
Dim ListAreaHeight As Long
ComboBoxWidth = Combo1.Width \ Screen.TwipsPerPixelX
ListAreaHeight = SendMessageLong(Combo1.hwnd, CB_GETITEMHEIGHT, 0, 0)
EditAreaHeight = SendMessageLong(Combo1.hwnd, CB_GETITEMHEIGHT, -1, 0)
NewComboBoxHeight = ListAreaHeight * 16 + 2 * EditAreaHeight
GetWindowRect Combo1.hwnd, Rectangle
Point.x = Rectangle.Left
Point.y = Rectangle.Top
ScreenToClient Me.hwnd, Point
MoveWindow Combo1.hwnd, Point.x, Point.y, ComboBoxWidth, NewComboBoxHeight, True
End Sub最后在form load时调用这个sub 就可以了。
SetComboBoxHeight