I have an odd requirement. Our data has ticks, which are time-related. Each tick may have from 0 to 50 data points in them. I want the ticks laid out on the scrollbar, so if you drag the handle, you scroll through ticks. But I want the arrows to change between data points, so that if you use one of the arrows to step through, you’ll see every data point.
Is it possible for me to get the events directly from the HScrollBar so I know whether the user clicked an arrow or dragged the handle?
You can indeed use
HScrollBarandVScrollBardirectly, although it doesn’t give you the positions in the way you say you want them. You can set the amount of space it moves when the user clicks an arrow (that would be theSmallIncrementandSmallDecrement) and when the user clicks in the scroller area (LargeIncrementandLargeDecrement). But you can’t set the amount of space it moves when the user is dragging the thumb.You could potentially move the scroller position when the user stops dragging (by rounding the resulting position), but that might confuse the user. Look into the
HScrollBar.Scrollevent and theScrollEventArgs.Typeproperty.It’s probably better to use the
TrackBarand add left and right arrow buttons to your UI. Making aHScrollBarwork the way you want is going to be difficult, and it probably wouldn’t look as nice as theTrackBar.