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
Public Function SetComboBoxHeight(objCB As ComboBox, _ TheHeight As Single) As Boolean On Error Resume Next Dim lHeight As Single lHeight = TheHeight * 1440 'inches to pixels lHeight = lHeight / Screen.TwipsPerPixelY Me.ScaleMode = vbPixels With objCB MoveWindow .hwnd, .Left, .Top, .Width, lHeight, 1 End With Me.ScaleMode = vbTwips
SetComboBoxHeight = Err.Number = 0 And Err.LastDllError = 0
End FunctionPrivate Sub Form_Load() Dim i As Integer For i = 0 To 36 Combo1.AddItem "list" & i Next i SetComboBoxHeight Combo1, 2 End Sub
2.窗体的scalemde要是twips Option Explicit
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
Public Function SetComboBoxHeight(objCB As ComboBox, _
TheHeight As Single) As Boolean
On Error Resume Next
Dim lHeight As Single
lHeight = TheHeight * 1440 'inches to pixels
lHeight = lHeight / Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
With objCB
MoveWindow .hwnd, .Left, .Top, .Width, lHeight, 1
End With
Me.ScaleMode = vbTwips
SetComboBoxHeight = Err.Number = 0 And Err.LastDllError = 0
End FunctionPrivate Sub Form_Load()
Dim i As Integer
For i = 0 To 36
Combo1.AddItem "list" & i
Next i
SetComboBoxHeight Combo1, 2
End Sub
Combo1.AddItem "****"
Combo1.AddItem "11111111"