Search Tools Links Login

Add Horizontal Scrollbar to Listbox


Automatically add a horizontal scrollbar to a listbox, quickly and completely. I wasnt satisfied with the ones on planet so I created my own.

Original Author: unknown

API Declarations

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const LB_SETHORIZONTALEXTENT = &H194

Code

Public Sub AddScroll(List As ListBox)
Dim i As Integer, intGreatestLen As Integer, lngGreatestWidth As Long
'Find Longest Text in Listbox
For i = 0 To List.ListCount - 1
If Len(List.List(i)) > Len(List.List(intGreatestLen)) Then
  intGreatestLen = i
End If
Next i
'Get Twips
lngGreatestWidth = List.Parent.TextWidth(List.List(intGreatestLen) + Space(1))
'Space(1) is used to prevent the last Character from being cut off
'Convert to Pixels
lngGreatestWidth = lngGreatestWidth Screen.TwipsPerPixelX
'Use api to add scrollbar
SendMessage List.hwnd, LB_SETHORIZONTALEXTENT, lngGreatestWidth, 0

End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 77 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.