Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGive a ListBox a horizontal scroll bar
Description
KeywordsListBox, scroll
CategoriesAPI, Controls
 
Use SendMessage to send the control the LB_SETHORIZONTALEXTENT message specifying the necessary width to display the list items.
 
Public Sub SetListboxScrollbar(ByVal lst As ListBox)
Dim i As Integer
Dim new_len As Long
Dim max_len As Long

    For i = 0 To lst.ListCount - 1
        new_len = 10 + lst.Parent.ScaleX( _
            lst.Parent.TextWidth(lst.List(i)), _
            lst.Parent.ScaleMode, vbPixels)
        If max_len < new_len Then max_len = new_len
    Next i

    SendMessage lst.hwnd, _
        LB_SETHORIZONTALEXTENT, _
        max_len, 0
End Sub
 
Thanks to Richard Wilkinson for converting the original version into a public subroutine in a module.
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated