VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Add Horizontal Scrollbar to Listbox


Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (16 Votes)

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

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

Rate Add Horizontal Scrollbar to Listbox

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

Download this snippet    Add to My Saved Code

Add Horizontal Scrollbar to Listbox Comments

No comments have been posted about Add Horizontal Scrollbar to Listbox. Why not be the first to post a comment about Add Horizontal Scrollbar to Listbox.

Post your comment

Subject:
Message:
0/1000 characters