Untuk tujuan tertentu, terkadang kita memerlukan sebuah fungsi untuk mengukur Item Heigh sebuah object ListBox dan di bawah ini merupakan salah satu contohnya dengan menggunakan fungsi API.
Option Explicit
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Const LB_GETITEMRECT As Long = &H198
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Function ListBoxItemHeight(lst As ListBox) As Integer
Dim rc As RECT, i As Long, dy As Long
If lst.ListCount = 0 Then Exit Function
SendMessage lst.hwnd, LB_GETITEMRECT, ByVal 0&, rc
dy = rc.Bottom - rc.Top
ListBoxItemHeight = (dy * Screen.TwipsPerPixelY)
End Function
Contoh penggunaan:
Private Sub Command1_Click()
List1.AddItem "A"
MsgBox ListBoxItemHeight(List1)
End Sub