HypernovaDesktop Components · docs
Binarymission
WinForms › Scroll Bar Marker › MarkerVerticalScrollBar

MarkerVerticalScrollBar

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.MarkerScrollBar

A vertical scroll bar that shows marks on its track – errors, warnings, bookmarks, changed regions – at the positions they belong to, so the user can see where they are in a long document and click to go there.

public class MarkerVerticalScrollBar : VerticalScrollBar

Inherits from / implements: VerticalScrollBar

Remarks

What it is for

It is a VerticalScrollBar in every other respect: range, position, events and themes work the same. On top of that it draws the objects in ScrollBarMarks, in the way an editor marks its scroll bar.

Marks

A mark's value is in the bar's own range units and is placed at the same point of the track as the thumb's top would be for that position. ScrollBarMarkBase.Alignment puts it at the left, centre or right of the bar.

Using it

Turn on ShouldEnableMarkerDrawing – it is off by default – add marks to ScrollBarMarks, and call Invalidate() after changing the list. Clicking a mark scrolls to it (ShouldScrollUponBookmarkClick); hovering over one with ScrollBarMarkBase.ToolTipInfo shows its tool tip.

Marks are hit tested where they were last drawn, so they respond to the mouse only once they have been painted.

Examples

Marking the error lines of a build log shown in a list box.

using Binarymission.WinForms.Controls.MarkerScrollBar;

var logBar = new MarkerVerticalScrollBar
{
    Location = new Point(buildLog.Right, buildLog.Top),
    Height = buildLog.Height,
    MaximumScrollRange = buildLog.Items.Count,
    LargeChange = buildLog.ClientSize.Height / buildLog.ItemHeight,
    SmallChange = 1,
    ShouldEnableMarkerDrawing = true,
};

for (int line = 0; line < buildLog.Items.Count; line++)
{
    var text = (string)buildLog.Items[line];
    if (!text.Contains(": error "))
        continue;

    logBar.ScrollBarMarks.Add(new ScrollBarShapeMark
    {
        Value = line,
        Size = new SizeF(8, 4),
        Alignment = ScrollBarMarkAlignment.Center,
        StartColor = Color.Firebrick,
        ToolTipTitle = "Line " + (line + 1),
        ToolTipInfo = text,
        ToolTipIcon = ToolTipIcon.Error,
    });
}

logBar.PositionChanged += (sender, e) => buildLog.TopIndex = (int)e.NewPosition;
Controls.Add(logBar);

See also

Members at a glance

Constructors
MarkerVerticalScrollBarInitialises a bar with an empty mark list, marker drawing off, click-to-scroll and tool tips on.
Properties
ScrollBarMarksGets the marks drawn on the bar.
ShouldDisplayToolTipInfoOnBookmarkGets or sets whether hovering over a mark shows its tool tip.
ShouldEnableMarkerDrawingGets or sets whether the marks in ScrollBarMarks are drawn.
ShouldScrollUponBookmarkClickGets or sets whether clicking a mark scrolls to it.
Methods
OnMouseDownScrolls to the mark under the pointer when ShouldScrollUponBookmarkClick is on; otherwise, or away from any mark, handles the press as an ordinary scroll bar does.
OnMouseHoverRaises MouseHover and shows the tool tip of the mark under the pointer, with its title, icon and balloon setting, unless a mouse button is down.
OnMouseMoveHides the tool tip once the pointer leaves the mark it belongs to, then does the scroll bar's own pointer tracking.
OnMouseUpRaises MouseUp and ends any drag, as an ordinary scroll bar does.
PaintScrollBarDraws the scroll bar, then each mark in ScrollBarMarks over its track while ShouldEnableMarkerDrawing is on.

Constructors

MarkerVerticalScrollBar

public MarkerVerticalScrollBar() : base()

Initialises a bar with an empty mark list, marker drawing off, click-to-scroll and tool tips on.

Properties

ScrollBarMarks

public IList<ScrollBarMarkBase> ScrollBarMarks

Gets the marks drawn on the bar.

Value
A list, empty to begin with, of ScrollBarShapeMark, ScrollBarRangeMark and ScrollBarImageMark objects. Never null.
Remarks

Marks are drawn in list order, so a later mark covers an earlier one where they overlap, and the first mark under the pointer is the one clicked or hovered.

The bar does not watch the list: call Invalidate() after adding, removing or changing marks. Nothing is drawn until ShouldEnableMarkerDrawing is true.

ShouldDisplayToolTipInfoOnBookmark

public bool ShouldDisplayToolTipInfoOnBookmark

Gets or sets whether hovering over a mark shows its tool tip.

Value
The default is true.
Remarks

The bar does not read this property: a mark with ScrollBarMarkBase.ToolTipInfo shows its tool tip on hover whatever it is set to. To have no tool tip, leave ScrollBarMarkBase.ToolTipInfo empty.

ShouldEnableMarkerDrawing

public bool ShouldEnableMarkerDrawing

Gets or sets whether the marks in ScrollBarMarks are drawn.

Value
true to draw them; the default is false, so a new bar shows no marks until this is turned on.
Remarks

Setting it repaints the bar at once. Marks are still hit tested where they were last drawn while it is off – at the bar's top-left corner if they never were.

ShouldScrollUponBookmarkClick

public bool ShouldScrollUponBookmarkClick

Gets or sets whether clicking a mark scrolls to it.

Value
true (the default) to set ScrollBarBase.Position to the clicked mark's ScrollBarMarkBase.Value.
Remarks

A press of any mouse button on a mark scrolls, and replaces the bar's own handling of that press: no arrow, track or thumb action, and no MouseDown event. The move raises ScrollBarBase.PositionChanged. While this is false, a press on a mark acts on the part of the bar beneath it.

Methods

OnMouseDown

protected override void OnMouseDown(MouseEventArgs e)

Scrolls to the mark under the pointer when ShouldScrollUponBookmarkClick is on; otherwise, or away from any mark, handles the press as an ordinary scroll bar does.

Parameters
e
The mouse data.

OnMouseHover

protected override void OnMouseHover(EventArgs e)

Raises MouseHover and shows the tool tip of the mark under the pointer, with its title, icon and balloon setting, unless a mouse button is down.

Parameters
e
The event data.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

Hides the tool tip once the pointer leaves the mark it belongs to, then does the scroll bar's own pointer tracking.

Parameters
e
The mouse data.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs e)

Raises MouseUp and ends any drag, as an ordinary scroll bar does.

Parameters
e
The mouse data.

PaintScrollBar

protected override void PaintScrollBar(Graphics g)

Draws the scroll bar, then each mark in ScrollBarMarks over its track while ShouldEnableMarkerDrawing is on.

Parameters
g
The surface to draw on.
Remarks

Each mark's drawn bounds are remembered for hit testing and tool tips.