Change the size of scrollbar in winforms

2019-05-14 14:35发布

问题:

I want to change the size of the actual bar/thumb part of the scrollbar in winforms but I can't find a way to do this. The thumb is about 1/10 of the actual scroll area regardless of how much there is to scroll. It's the same whether I have to scroll down 1 line or 1000 line. I want the size of it to adjust depending on how much there is to scroll or at the very least make it something like 50% the size of the scroll area.

回答1:

The from contains some property to adjust the scrolling such as: AutoScrollMargin, AutoScrollMinSize, AutoScrollOffset, and it also have HorizontalScroll and VerticalScroll, the last two properties represents the virtecal and horizontal scroll bar of the form, they also expose some properties like Minimum, Maximum, SmallChange, LargeChange, Value.., If using all those does not satisfy your requirements, then you should use a custom Scrollbar. Add ScrollBar to the form and disable the form scroll bar, and adjust your custom scroll bar whenever a controls added to form or changes its size...



回答2:

Actually I got it. this.vScrollBar1.LargeChange = this.vScrollBar1.Maximum / 2; changes the thumb to half the track length.



回答3:

The thumb bar size of a scrollbar control is directly proportional to the difference between that control's ScrollBarName.Maximum and ScrollBarName.LargeChange values.

To make use of ScrollBarName.LargeChangea proportional offset value is needed for ScrollBarName.Maximumso that the scrollbar control when used behaves as intended. The following example demonstrates how this offset calculation is made and how it is applied in a practical application context.

Offset Calculation:

ScrollBarName.Maximum = MyMaximum + MyLargeChange - 1 ' LargeChange Usage Offset Calcualtion

Application Context:

'*** Using Simplified Values To Avoid Confusion ***

Dim ScrollBarName As New VScrollBar ' Or HScrollBar Control
Dim MyMaximum As Integer = 100 ' Your "off screen" calculated value
Dim MySmallChange As Integer = 10 ' MySmallChange <= MyLargeChange <= MyMaximum
Dim MyLargeChange As Integer = 50 ' MyLargeChange <= MyMaximum (Example produces thumbar sized {(MyLargeChange / ScrollBarName.Maximum) %} Clientsize.width
Me.controls.add(ScrollBarName) ' Add Your Control
ScrollBarName.Dock = DockStyle.Right ' Dock bottom for HScrollBar

ScrollBarName.SmallChange = MySmallChange
ScrollBarName.LargeChange = MyLargeChange
ScrollBarName.Maximum = MyMaximum + MyLargeChange - 1 ' LargeChange Usage Offset Calcualtion
ScrollBarName.Value = 20 ' The scrollBar movement value whereby ScrollBarName.Value <= MyMaximum