Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
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-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated