Advertisement
5_2007-2008 Windows API Call/ Explanation #177887

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.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
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
Original Comments (3)
Recovered from Wayback Machine