Results 1 to 5 of 5

Thread: Get Thumb Size of Scrollbar

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Get Thumb Size of Scrollbar

    I'm wanting to know how to get the current thumb size of both the HScrollBar and the VScrollBar. At first I thought that it would be simple with using the Horizontal and Vertical ScrollBarThumbWidth found in the SystemInformation namespace, but it turns out that that just returns the default size of the thumb width. What I need is the current width of a particular HScrollBar or VScrollBar, how am I able to do that?

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,254

    Re: Get Thumb Size of Scrollbar

    Well VerticalScrollBarThumbHeight and HorizontalScrollBarThumbWidth seem to be reporting exactly what Windows scrollbars are currently sized to, quick test... I switch Win7 to basic theme, change scrollbar size from default 17 to 30, VB reported 30 for both properties above, set it back to 17, VB reports 17, switch back to Win7 theme and VB reports 17.

    Could it be your scrollbars in question are possibly custom drawn?

    For the heck of it I added a VB VScrollBar control to a form thinking it wouldn't be effected by the windows scrollbar setting, but the height of the thumbs actually did change.
    Attachment 122823

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Re: Get Thumb Size of Scrollbar

    Could it be your scrollbars in question are possibly custom drawn?
    Yeah, this is all that I'm doing:
    Code:
    Option Strict On
    Option Explicit On
    Public Class CustomHScrollBar
        Inherits HScrollBar
    
        Public Function ThumbSize() As Integer
            Return SystemInformation.HorizontalScrollBarThumbWidth
        End Function
    
    End Class
    I changed the LargeChange to 50 and left everything else default. I used a MessageBox to display the control's ThumbSize method and it still returns 17.

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,254

    Re: Get Thumb Size of Scrollbar

    Quote Originally Posted by dday9 View Post
    I changed the LargeChange to 50 and left everything else default. I used a MessageBox to display the control's ThumbSize method and it still returns 17.
    Oh, I'm not aware of any straight forward way to get the size of the actual thumb.
    I thought those two sys-info properties were actually referring to the repeatable buttons on the ends of the bar.

  5. #5
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Get Thumb Size of Scrollbar

    If you are talking about the System.Windows.Forms.VScrollBar, I think these calculations should get you that value.

    Code:
    Dim thumbTrackHeightPx As Int32 = VScrollBar1.ClientRectangle.Height - (2 * SystemInformation.VerticalScrollBarArrowHeight)
    Dim thumbHeight As Int32 = thumbTrackHeightPx * VScrollBar1.LargeChange \ ((VScrollBar1.Maximum - VScrollBar1.Minimum) + 1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width