How to know if the scrollbar is showing inside a listbox?

Posted on 2005-05-12
Last Modified: 2010-04-23

I try to find a way to ask my listbox if the HorizontalScrollbar or the VerticalScrollbar is showing.
Is there a way?

Question by:slabrie99
    LVL 96

    Accepted Solution

    Public Class Control_Library

      Private Declare Function GetWindowLong _
        Lib "user32" Alias "GetWindowLongA" _
          (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer

      Private Const GWL_STYLE As Short = (-16)

      Public Shared Function HasHorizontalScrollbar(ByVal ctrl As System.Windows.Forms.Control) As Boolean

        Const WS_HSCROLL As Integer = &H100000

        Return GetWindowLong(ctrl.Handle, GWL_STYLE) And WS_HSCROLL

      End Function 'HasHorizontalScrollbar'

      Public Shared Function HasVerticalScrollbar(ByVal ctrl As System.Windows.Forms.Control) As Boolean

        Const WS_VSCROLL = &H200000

        Return GetWindowLong(ctrl.Handle, GWL_STYLE) And WS_VSCROLL

      End Function 'HasVerticalScrollbar'

    End Class

    Dim vertical As Boolean = Control_Library.HasVerticalScrollbar(Me.ListBox1)

    LVL 27

    Expert Comment

    What is the purpose for knowing this?

    Author Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now