Reputation: 11
Just wondering if anyone know's how to remove scroll bars from a listbox in VB 6.0? As I want to add a 'global' scroll bar for multiple listboxes. I have searched online, but all of the solutions require the code to be placed in the click event of the list box.
Upvotes: 1
Views: 1730
Reputation: 16358
You can hide the scrollbars using the Windows API. Here's a sample project to get you started. Add a ListBox (List1) to a form and add the following code:
Private Declare Function ShowScrollBar Lib "user32" _
(ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
Private Const SB_VERT = 1
Private Sub HideVertScrollBar(LB As ListBox)
Call ShowScrollBar(LB.hwnd, SB_VERT, 0&)
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 25
List1.AddItem "Item " & i
Next
HideVertScrollBar List1
End Sub
Private Sub List1_Click()
HideVertScrollBar List1
End Sub
If you only call HideVertScrollBar
in Form_Load
, when you manually scroll (using the arrow keys), the scrollbar shows up again. We fix this by calling HideVertScrollBar
in List1_Click
as well.
Upvotes: 1