devxlogo

Hide and Show a control’s scrollbars

Hide and Show a control’s scrollbars

Most VB controls don’t let you determine whether they should display a scrollbar or not. For example, a VB ListBox control displays a vertical scrollbar only when the number of its items is larger than the number of visible items. If you want to directly control individual scrollbars, you can use the following two API functions:

Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, _    ByVal wBar As Long, ByVal bShow As Long) As LongPrivate Const SB_HORZ = 0Private Const SB_VERT = 1Private Const SB_BOTH = 3

For example, you can display the vertical scrollbar of a ListBox control, even if the ListBox doesn’t contain any item, using this code:

ShowScrollBar List1.hWnd, SB_VERT, True

This trick works with several other controls, e.g. ComboBox and TreeView controls, but not all. For example, while you can add a scrollbar to a ListView control, as soon as VB redraws the control (for example, after adding an item), the original settings are restored.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist