Scrollbars in richtext box visible?

Posted on 2006-05-18
Last Modified: 2012-05-05
This is a question that has been asked in many variations, but I have yet to find an answer.

I have a richtext box and I want to know, at any given time, if the vertical scroll bar is visible. I have other hooks in place to track when the scroll in scrolled (using GetScrollInfo), but I am trying to figure out if it is visible. I.e. When the user resizes the form, is the scroll bar still visible.  Any thoughts?
Question by:IOFDSYS
    1 Comment
    LVL 85

    Accepted Solution


        Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
        Public Const WS_HSCROLL = &H100000
        Public Const WS_VSCROLL = &H200000
        Public Const GWL_STYLE = (-16)

        Private Function HasVerticalScrollBar(ByVal handle As IntPtr) As Boolean
            Return (GetWindowLong(handle, GWL_STYLE) And WS_VSCROLL) = WS_VSCROLL
        End Function

        Private Function HasHorizontalScrollBar(ByVal handle As IntPtr) As Boolean
            Return (GetWindowLong(handle, GWL_STYLE) And WS_HSCROLL) = WS_HSCROLL
        End Function

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Debug.WriteLine("Vertical: " & HasVerticalScrollBar(RichTextBox1.Handle))
            Debug.WriteLine("Horizontal: " & HasHorizontalScrollBar(RichTextBox1.Handle))
        End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    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…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 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

    12 Experts available now in Live!

    Get 1:1 Help Now