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
 
 
 
 
 
TitleAdd a horizontal scroll bar to a ListBox
KeywordsListBox, scroll, hscroll, scrollbar, horizontal
CategoriesControls
 
Thanks to 10Tec Company.

This program's CLBHScroll class attaches to a ListBox. When you call the class's Add method, it adds an item to the ListBox and then uses the SendMessageByLong API function to set the ListBox's text extent. This tells the ListBox how wide its entries are and makes it display a horizontal scroll bar if necessary.

 
Public Sub Init(ByRef pListBox As ListBox)
   Set mvarListBox = pListBox
   mvarListBox.Clear
   m_lMaxItemWidth = 0
End Sub

' The following routine adds a string to a specified list
' box
' and displays the horizontal scroll bar in it if required
Public Sub AddItem(ByRef psItemText As String)
   Dim m As Long
   
   mvarListBox.AddItem psItemText
   
   m = mvarListBox.Parent.TextWidth(psItemText)
   
   If m > m_lMaxItemWidth Then
      m_lMaxItemWidth = m
      SendMessageByLong mvarListBox.hwnd, _
          LB_SETHORIZONTALEXTENT, _
         m / Screen.TwipsPerPixelX + _
             GetSystemMetrics(SM_CXVSCROLL) + 2, 0
   End If
   
   SendMessageByLong mvarListBox.hwnd, WM_VSCROLL, _
       SB_BOTTOM, 0
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated