ChgNumItemCombo




Private Type POINTAPI
x As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ScreenToClient Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINTAPI) As Long
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 Sub SetComboListAreaSize(objForm As Form, cboCombo As ComboBox)
'

' Makes the dropdown area of a combo box larger

'

Dim pt As POINTAPI
Dim rec As RECT
Dim iItemWidth As Integer
Dim iItemHeight As Integer
Dim iOldScaleMode As Integer
Dim nRet As Variant
'Change the Scale Mode on the form to Pixels.

iOldScaleMode = objForm.ScaleMode
objForm.ScaleMode = vbPixels
'Set the Width and new Height of the combo box.

iItemWidth = cboCombo.Width
iItemHeight = objForm.ScaleHeight - cboCombo.Top - 5
objForm.ScaleMode = iOldScaleMode
'Get the coordinates relative to the screen,

nRet = GetWindowRect(cboCombo.hwnd, rec)
pt.x = rec.Left
pt.Y = rec.Top
'then the coordinates relative to the form.

nRet = ScreenToClient(objForm.hwnd, pt)
'Finally, resize the combo box.

nRet = MoveWindow(cboCombo.hwnd, pt.x, pt.Y, iItemWidth, iItemHeight, 1)
End Sub











( chgnumitemcombo.html )- by Paolo Puglisi - Modifica del 17/12/2023