Make your own free website on Tripod.com

Add Horizonal Scroll Bar To ListBox

'Add 1 ListBox to your form. Add 1 long string to the ListBox list.
'Insert the following code to your form:

Private Declare Function SendMessageByNum Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal _
wParam As Long, ByVal lParam As Long) As Long
Const LB_SETHORIZONTALEXTENT = &H194

Private Sub Form_Load()
Static x As Long
'The width of the scroll bar will be the width of  the string in 'List1.List(0)'.
'Replace all 'List1.List(0)' with the longest item in your ListBox's list.

If x < TextWidth(List1.List(0) & " ") Then
x = TextWidth(List1.List(0) & " ")
If ScaleMode = vbTwips Then x = x / Screen.TwipsPerPixelX
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0
End If
End Sub

Go Back