Scrollbars in richtext box visible?

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?
Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:

    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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.