HorizontalScrollBar
A themeable horizontal scroll bar: arrow buttons at the left and right ends, a thumb sized to the share of the range in view, and a right-click menu of scroll commands.
public class HorizontalScrollBar : ScrollBarBase
Inherits from / implements: ScrollBarBase
Remarks
Using it
Place it under the view it scrolls, set ScrollBarBase.MaximumScrollRange to the content's
width and ScrollBarBase.LargeChange to the visible width (in the same units), and move the
view in ScrollBarBase.PositionChanged. The range model, the thickness and the appearance are
described on ScrollBarBase.
Mouse and keyboard
- An arrow moves by
ScrollBarBase.SmallChangeand a click on the track either side of the thumb byScrollBarBase.LargeChange; holding either repeats everyAutoScrollIntervalmilliseconds until the button comes up or Esc is pressed. - The thumb can be dragged; Shift with the wheel, and Left / Right, also scroll while the bar has the focus.
- Right-click opens Scroll Here, Left Edge, Right Edge, Page Left, Page Right, Scroll Left and Scroll
Right (see
IsDefaultScrollContextMenuEnabled).
Events
Mouse actions raise LineLeft / LineRight, PageLeft /
PageRight, ThumbLeft / ThumbRight and Scroll.
Every change of position, from any source, raises ScrollBarBase.PositionChanged.
Examples
using Binarymission.WinForms.Controls.ScrollBars;
// A floor plan wider than its 600 pixel viewport, panned by a themed bar.
var viewport = new Panel { Location = new Point(12, 12), Size = new Size(600, 260) };
var floorPlan = new PictureBox
{
Image = Image.FromFile("warehouse-floor.png"),
SizeMode = PictureBoxSizeMode.AutoSize,
};
viewport.Controls.Add(floorPlan);
var panBar = new HorizontalScrollBar
{
Location = new Point(12, viewport.Bottom),
Width = viewport.Width,
MaximumScrollRange = floorPlan.Width,
LargeChange = viewport.Width,
SmallChange = 24,
};
panBar.ScrollBarRenderingConfigurator.ColorTheme = ColorTheme.OfficeSilver;
panBar.PositionChanged += (sender, e) => floorPlan.Left = -(int)e.NewPosition;
Controls.Add(viewport);
Controls.Add(panBar);See also
Members at a glance
| Constructors | |
|---|---|
HorizontalScrollBar | Initialises a stand-alone horizontal bar with its right-click menu enabled. Add it to a form or panel and set its range. |
HorizontalScrollBar | Initialises a horizontal bar owned by a host control, which it serves and docks into. |
| Properties | |
DefaultSize | Gets the size a new bar starts at: 184 by 17 pixels. The height is then set from
ScrollBarBase.HorizontalScrollBarHeight. |
IsDefaultScrollContextMenuEnabled | Gets or sets whether right-clicking the bar opens its built-in menu of scroll commands. |
ShouldUseExtendedMenuControlForContextMenu | Gets or sets whether the built-in right-click menu is built from the suite's extended menu items. |
VerticalScrollBarWidth | Not used by this orientation: returns ScrollBarBase.HorizontalScrollBarHeight and ignores assignments. Hidden
from the designer and from IntelliSense. |
| Methods | |
GetNavigatorControlRect | Returns the bounds of one of the two arrow buttons: a square as thick as the bar, at the left or right end. |
GetThumbArtefactRectangle | Returns the thumb's bounds: its length is the track's length times ScrollBarBase.LargeChange
over the range, at least 6 pixels, and its offset maps ScrollBarBase.Position onto the
track. |
HitTest | Returns the part of the bar at a point: an arrow, the track either side of the thumb, or the thumb. |
OnMouseDown | Raises Control.MouseDown and, for the left button, acts on the part under the pointer: an
arrow steps by ScrollBarBase.SmallChange, the track by ScrollBarBase.LargeChange
(both repeating while held), and the thumb starts a drag. |
OnMouseEnter | Raises Control.MouseEnter and highlights the arrow or thumb under the pointer. |
OnMouseLeave | Raises Control.MouseLeave and returns the arrows and the thumb to their idle look. |
OnMouseMove | Highlights the arrow or thumb under the pointer and, during a drag, moves the thumb with it. |
OnMouseUp | Raises Control.MouseUp and, for the left button, ends a thumb drag: the final thumb event,
then Scroll with ThumbPosition and EndScroll. |
OnResize | Raises Control.Resize and repaints the bar at its new size. |
PaintScrollBar | Draws the bar: the track, the two arrow buttons, the thumb, the gripper and the outer border. A disabled bar shows only its track and border. |
PerformSizeRefresh | Lays the bar out. Self-positioning, it runs along the bottom of the served control's client area, inset
by ScrollBarBase.PaddingGap and stopping short of a vertical bar that shares the control;
otherwise only its height is set, to ScrollBarBase.HorizontalScrollBarHeight. |
| Events | |
HorizontalScrollPositionChanged | Occurs after a command on the bar's right-click menu has moved the position: Scroll Here, Left Edge, Right Edge, Scroll Left or Scroll Right. |
LineLeft | Occurs when the left arrow moves the position left by ScrollBarBase.SmallChange: on the
click, and on each repeat while it is held. |
LineRight | Occurs when the right arrow moves the position right by ScrollBarBase.SmallChange: on the
click, and on each repeat while it is held. |
PageLeft | Occurs when a click on the track left of the thumb, or the Page Left menu command, moves the position
left by ScrollBarBase.LargeChange; repeated while the track is held. |
PageRight | Occurs when a click on the track right of the thumb, or the Page Right menu command, moves the position
right by ScrollBarBase.LargeChange; repeated while the track is held. |
Scroll | Occurs as the user scrolls with the mouse, in the form of the framework's
Scroll event. |
ThumbLeft | Occurs when a drag moves the thumb left, for every step of the drag, the last one at release included. |
ThumbRight | Occurs when a drag moves the thumb right, for every step of the drag, the last one at release included. |
Constructors
HorizontalScrollBar
Initialises a stand-alone horizontal bar with its right-click menu enabled. Add it to a form or panel and set its range.
HorizontalScrollBar
Initialises a horizontal bar owned by a host control, which it serves and docks into.
Parameters
parent- The host, usually the suite's scrolling panel or scrollable picture box. Must not be
null.
Remarks
A bar created this way has no right-click menu until IsDefaultScrollContextMenuEnabled
is set.
Properties
DefaultSize
Gets the size a new bar starts at: 184 by 17 pixels. The height is then set from
ScrollBarBase.HorizontalScrollBarHeight.
VerticalScrollBarWidth
Not used by this orientation: returns ScrollBarBase.HorizontalScrollBarHeight and ignores assignments. Hidden
from the designer and from IntelliSense.
Methods
GetThumbArtefactRectangle
Returns the thumb's bounds: its length is the track's length times ScrollBarBase.LargeChange
over the range, at least 6 pixels, and its offset maps ScrollBarBase.Position onto the
track.
Returns
The thumb's bounds, in client coordinates.
HitTest
Returns the part of the bar at a point: an arrow, the track either side of the thumb, or the thumb.
Parameters
point- The point, in the bar's client coordinates.
Returns
OnMouseDown
Raises Control.MouseDown and, for the left button, acts on the part under the pointer: an
arrow steps by ScrollBarBase.SmallChange, the track by ScrollBarBase.LargeChange
(both repeating while held), and the thumb starts a drag.
Parameters
e- The mouse data.
Remarks
While an arrow or the track is held, the call does not return until the button comes up: it runs its own message loop to repeat the step.
OnMouseEnter
Raises Control.MouseEnter and highlights the arrow or thumb under the pointer.
Parameters
e- The event data.
OnMouseLeave
Raises Control.MouseLeave and returns the arrows and the thumb to their idle look.
Parameters
e- The event data.
OnMouseMove
Highlights the arrow or thumb under the pointer and, during a drag, moves the thumb with it.
Parameters
e- The mouse data.
OnMouseUp
Raises Control.MouseUp and, for the left button, ends a thumb drag: the final thumb event,
then Scroll with ThumbPosition and EndScroll.
Parameters
e- The mouse data.
OnResize
Raises Control.Resize and repaints the bar at its new size.
Parameters
e- The event data.
PaintScrollBar
Draws the bar: the track, the two arrow buttons, the thumb, the gripper and the outer border. A disabled bar shows only its track and border.
Parameters
g- The surface to draw on.
PerformSizeRefresh
Lays the bar out. Self-positioning, it runs along the bottom of the served control's client area, inset
by ScrollBarBase.PaddingGap and stopping short of a vertical bar that shares the control;
otherwise only its height is set, to ScrollBarBase.HorizontalScrollBarHeight.
Events
HorizontalScrollPositionChanged
Occurs after a command on the bar's right-click menu has moved the position: Scroll Here, Left Edge, Right Edge, Scroll Left or Scroll Right.
Remarks
Raised by those menu commands only – the Page commands raise PageLeft /
PageRight instead. To follow every change of position, use
ScrollBarBase.PositionChanged.
LineLeft
Occurs when the left arrow moves the position left by ScrollBarBase.SmallChange: on the
click, and on each repeat while it is held.
Remarks
Not raised when the position was already at the start, nor by the keyboard or the wheel.
LineRight
Occurs when the right arrow moves the position right by ScrollBarBase.SmallChange: on the
click, and on each repeat while it is held.
Remarks
Not raised when the position was already at the end, nor by the keyboard or the wheel.
PageLeft
Occurs when a click on the track left of the thumb, or the Page Left menu command, moves the position
left by ScrollBarBase.LargeChange; repeated while the track is held.
PageRight
Occurs when a click on the track right of the thumb, or the Page Right menu command, moves the position
right by ScrollBarBase.LargeChange; repeated while the track is held.
Scroll
Occurs as the user scrolls with the mouse, in the form of the framework's
Scroll event.
Remarks
Type is SmallDecrement / SmallIncrement for the arrows, LargeDecrement /
LargeIncrement for the track, ThumbTrack while the thumb is dragged, ThumbPosition
then EndScroll when it is released, and EndScroll when a held arrow or track is released.
First follows a move that reaches the start of the range. OldValue and NewValue are
the positions, truncated to whole units.
Last follows a move that reaches the end of the range (ScrollBarBase.MaximumScrollRange
minus ScrollBarBase.LargeChange, where the position stops).
The keyboard, the wheel and setting ScrollBarBase.Position in code do not raise it.
ThumbLeft
Occurs when a drag moves the thumb left, for every step of the drag, the last one at release included.
Remarks
ThumbEventArgs.ChangeDelta is the distance moved since the previous step, in whole range
units.
ThumbRight
Occurs when a drag moves the thumb right, for every step of the drag, the last one at release included.
Remarks
ThumbEventArgs.ChangeDelta is the distance moved since the previous step, in whole range
units.