HypernovaDesktop Components · docs
Binarymission
WinForms › Scroll Bars

Scroll Bars

.NET Framework 4.8.NET 6 / 8 / 10v3.1.0WinForms

The drawn, themeable scroll bar that VerticalScrollBar and HorizontalScrollBar are built on: range, position, line and page steps, colours and custom renderers in one place.

20public types
199public members
2namespaces

Assembly

AssemblyBinarymission.WinForms.Controls.ScrollBars.dll
Root namespaceBinarymission.WinForms.Controls.ScrollBars
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10
Depends onBinaryMenu

Overview

What it is for

Use a VerticalScrollBar or a HorizontalScrollBar wherever a form needs a scroll bar that matches its theme – beside a custom-drawn view, a long preview, a timeline – or let a host such as the suite's scrolling panel and scrollable picture box create and dock them for you. This class cannot be created directly; it holds everything the two orientations share.

The range model

The range runs from MinimumScrollRange (0) to MaximumScrollRange, in whatever units the application scrolls in – pixels of a picture, rows of a report. LargeChange is how much of that range is in view at once: it sets the thumb's length (the track length times LargeChange over the range, never less than 6 pixels) and one page step. Position is the first unit in view, so it runs from 0 to MaximumScrollRange minus LargeChange; values outside are clamped. SmallChange is one arrow click, arrow key or wheel notch.

Knowing when it scrolled

  • PositionChanged – every change of Position, whatever caused it. The one to use for keeping a view in step.
  • The orientation's own line, page and thumb events (LineUp, PageDown, ThumbLeft ...) – raised for mouse actions on the arrows, the track and the thumb.
  • The orientation's Scroll event – the same mouse actions in the framework's ScrollEventArgs form, for code written against the standard scroll bar.

The keyboard (arrow keys, and Page Up / Page Down on the vertical bar) and the mouse wheel change Position directly, so they raise PositionChanged only.

Appearance

Colours, images and the auto-repeat rate live on ScrollBarRenderingConfigurator; pick a ColorTheme there and adjust individual colours after it. To draw a part entirely yourself, assign ScrollBarTrackRenderer, ScrollBarThumbRenderer, ScrollBarThumbGripperRenderer or ScrollBarNavigationButtonRenderer.

Thickness is in device pixels

Unlike the suite's other metrics, VerticalScrollBarWidth and HorizontalScrollBarHeight are device pixels. Left alone, they follow the system scroll bar size for the display the bar is on (17 at 96 DPI) and follow the window to a display at another scale; a value you assign is used as given, on every display.

Getting started

A themed vertical bar scrolling a tall invoice page inside a fixed viewport.

using Binarymission.WinForms.Controls.ScrollBars;

var viewport = new Panel { Location = new Point(12, 12), Size = new Size(420, 300) };
var invoicePage = new Panel { Size = new Size(420, 1200), BackColor = Color.White };
viewport.Controls.Add(invoicePage);

var pageBar = new VerticalScrollBar
{
    Location = new Point(436, 12),
    Height = 300,
    MaximumScrollRange = 1200,   // the page's height, in pixels
    LargeChange = 300,           // the part of it the viewport shows
    SmallChange = 40,
};
pageBar.ScrollBarRenderingConfigurator.ColorTheme = ColorTheme.OfficeBlue;

// One handler covers arrows, track, thumb, keyboard and wheel.
pageBar.PositionChanged += (sender, e) => invoicePage.Top = -(int)e.NewPosition;

Controls.Add(viewport);
Controls.Add(pageBar);

API reference

Binarymission.WinForms.Controls.ScrollBars

enum ArrowDrawingArtefactWhich way the arrow on a scroll bar's arrow button points, as handed to Draw.
enum ColorThemeThe built-in colour themes a scroll bar can be drawn in; set one through ColorTheme.
enum ControlVisualStateThe visual state of a part of a scroll bar - an arrow button or the thumb - as handed to a custom renderer.
class HorizontalScrollBarA 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.
interface IScrollBarNavigationButtonRendererDraws a scroll bar's arrow buttons. Implement it and assign it to ScrollBarNavigationButtonRenderer to replace the built-in buttons; the bar's behaviour is unchanged.
interface IScrollBarThumbGripperRendererDraws the grip marks across a scroll bar's thumb. Implement it and assign it to ScrollBarThumbGripperRenderer to replace the built-in ridges.
interface IScrollBarThumbRendererDraws a scroll bar's thumb. Implement it and assign it to ScrollBarThumbRenderer to replace the built-in thumb; its size and position still come from the bar.
interface IScrollBarTrackRendererDraws the track of a scroll bar - the background its arrows and thumb sit on. Implement it and assign it to ScrollBarTrackRenderer to replace the built-in fill.
interface IScrollerPanelImplemented by a scrolling host that shows both scroll bars and wants the corner square between them filled: it tells the bars when its layout changes, and the colour for the square.
interface IScrollersDockHostImplemented by a control that creates and docks the suite's scroll bars inside itself, such as the suite's scrolling panel and scrollable picture box.
class PositionChangedArgsData for PositionChanged and the menu-command position events: the position before and after the change.
class ScrollBarBaseThe drawn, themeable scroll bar that VerticalScrollBar and HorizontalScrollBar are built on: range, position, line and page steps, colours and custom renderers in one place.
enum ScrollBarInteractionTargetThe part of a scroll bar at a point, as returned by HitTest.
class ScrollBarRenderingConfiguratorThe look of a scroll bar - colours, gradients, images, gripper - and how fast it repeats while an arrow is held. Every ScrollBarBase has one, in its ScrollBarRenderingConfigurator property.
class ScrollerPanelEventArgsData for ScrollerPanelUpdated: what a scrolling host tells the scroll bars it hosts when its layout changes.
class ThumbEventArgsData for the thumb events (ThumbUp, ThumbLeft and their opposites): how far one step of a drag moved the position.
class VerticalScrollBarA themeable vertical scroll bar: arrow buttons at the top and bottom, a thumb sized to the share of the range in view, and a right-click menu of scroll commands.

Binarymission.WinForms.Controls.ScrollBars.Designers

class HorizontalScrollBarControlDesignerDesign-time support for the horizontal scroll bar: it lets the bar be moved and resized on the design surface and passes clicks on it to the bar, so its arrows and thumb work in the designer.
class ScrollBarRenderingConfiguratorTypeConverterLets the property grid expand a ScrollBarRenderingConfigurator into its individual properties.
class VerticalScrollBarControlDesignerDesign-time support for the vertical scroll bar: it lets the bar be moved and resized on the design surface and passes clicks on it to the bar, so its arrows and thumb work in the designer.