Visual Basic Programming Code Examples
Visual Basic > Forms Code Examples
Show and Hide Listbox Scroll Bars at Runtime
Show and Hide Listbox Scroll Bars at Runtime
The following routines show and hide listbox scroll bars at runtime:
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
'Purpose : Hides/Shows the Horizontal Scroll bar on a list box
'Inputs : lbListBox Listbox to alter
' bShow If True shows Horizontal Scroll bar,
' else hides bar.
'Outputs : N/A
Sub ListBoxHorScroll(lbListBox As ListBox, bShow As Boolean)
Const SB_HORZ = 0, SB_CTL = 2, SB_BOTH = 3
If bShow Then
Call ShowScrollBar(lbListBox.hwnd, SB_HORZ, 1&)
Else
Call ShowScrollBar(lbListBox.hwnd, SB_HORZ, 0&)
End If
End Sub
'Purpose : Hides/Shows the Vertical Scroll bar on a list box
'Inputs : lbListBox Listbox to alter
' bShow If True shows Vertical Scroll bar,
' else hides bar.
'Outputs : N/A
Sub ListBoxVertScroll(lbListBox As ListBox, bShow As Boolean)
Const SB_VERT = 1, SB_CTL = 2, SB_BOTH = 3
If bShow Then
Call ShowScrollBar(lbListBox.hwnd, SB_VERT, 1&)
Else
Call ShowScrollBar(lbListBox.hwnd, SB_VERT, 0&)
End If
End Sub