MarkerVerticalScrollBar
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
ScrollBarShapeMark– a rectangle or oval, solid or gradient, centred on itsScrollBarMarkBase.Value.ScrollBarRangeMark– a band fromScrollBarMarkBase.ValuetoScrollBarRangeMark.EndValue.ScrollBarImageMark– a small image, such as an icon.
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 | |
|---|---|
MarkerVerticalScrollBar | Initialises a bar with an empty mark list, marker drawing off, click-to-scroll and tool tips on. |
| Properties | |
ScrollBarMarks | Gets the marks drawn on the bar. |
ShouldDisplayToolTipInfoOnBookmark | Gets or sets whether hovering over a mark shows its tool tip. |
ShouldEnableMarkerDrawing | Gets or sets whether the marks in ScrollBarMarks are drawn. |
ShouldScrollUponBookmarkClick | Gets or sets whether clicking a mark scrolls to it. |
| Methods | |
OnMouseDown | 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. |
OnMouseHover | 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. |
OnMouseMove | Hides the tool tip once the pointer leaves the mark it belongs to, then does the scroll bar's own pointer tracking. |
OnMouseUp | Raises MouseUp and ends any drag, as an ordinary scroll bar does. |
PaintScrollBar | Draws the scroll bar, then each mark in ScrollBarMarks over its track while
ShouldEnableMarkerDrawing is on. |
Constructors
MarkerVerticalScrollBar
Initialises a bar with an empty mark list, marker drawing off, click-to-scroll and tool tips on.
Properties
ScrollBarMarks
Gets the marks drawn on the bar.
- Value
- A list, empty to begin with, of
ScrollBarShapeMark,ScrollBarRangeMarkandScrollBarImageMarkobjects. Nevernull.
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
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
Gets or sets whether the marks in ScrollBarMarks are drawn.
- Value
trueto draw them; the default isfalse, 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
Gets or sets whether clicking a mark scrolls to it.
- Value
true(the default) to setScrollBarBase.Positionto the clicked mark'sScrollBarMarkBase.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
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
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
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
Raises MouseUp and ends any drag, as an ordinary scroll bar does.
Parameters
e- The mouse data.
PaintScrollBar
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.