HypernovaDesktop Components · docs
Binarymission
WinForms › Spinner › BinaryNumericUpDown

BinaryNumericUpDown

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

A numeric up-down box with a flat, single-line border and spin buttons in colours you choose – for quantities, prices, percentages and any other number the user types or steps through.

public class BinaryNumericUpDown : NumericUpDown

Inherits from / implements: NumericUpDown

Remarks

What it is for

A drop-in replacement for NumericUpDown: everything the standard control does – the range, the increment, decimal places, thousands separators, hexadecimal, keyboard and accessibility – works unchanged. What it adds is the look: a flat border that lights up in BorderColor, and spin buttons drawn in three states – resting, hot (under the pointer or holding the focus) and pressed.

Appearance

The button colours follow the Windows colour scheme until they are set. The spin buttons widen with the font, so a large font or a high display scale keeps them in proportion to the text.

Examples

A quantity box on an order form that rests borderless, lights up in steel blue, and updates the order total as it changes.

using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.InputControls;

const decimal unitPrice = 4.75m;
var totalLabel = new Label { Location = new Point(150, 19), AutoSize = true };

var quantity = new BinaryNumericUpDown
{
    Location = new Point(16, 16),
    Width = 120,
    Minimum = 1,
    Maximum = 500,
    Value = 12,
    ShowBorderAlways = false,
    BorderColor = Color.SteelBlue,
    UpDownButtonOnFocusBackColor = Color.AliceBlue,
    UpDownArrowPressedBackColor = Color.LightSteelBlue,
    UpDownArrowsColor = Color.DarkSlateBlue
};

quantity.ValueChanged += (sender, e) =>
    totalLabel.Text = (quantity.Value * unitPrice).ToString("C");

orderForm.Controls.Add(quantity);
orderForm.Controls.Add(totalLabel);

Members at a glance

Constructors
BinaryNumericUpDownInitialises the control with flat drawing on, the border shown at all times and the button colours taken from the Windows colour scheme.
Properties
BorderColorGets or sets the colour of the control's one-pixel border while it is hot, and of the outline round hot spin buttons.
BorderStyleGets or sets the border style, which this control keeps at BorderStyle.Fixed3D.
DrawStyleIsFlatGets or sets whether the control is drawn flat, with the colours set on it, or with the standard 3D look.
ShowBorderAlwaysGets or sets whether the border and spin buttons are shown in their hot colours at all times, rather than only while the pointer is over the control or it has the focus.
UpDownArrowPressedBackColorGets or sets the colour a spin button is filled with while it is held down.
UpDownArrowsColorGets or sets the colour of the up and down arrows on the spin buttons.
UpDownButtonNormalBackColorGets or sets the colour the spin buttons are filled with at rest – when the pointer is elsewhere and the control does not have the focus.
UpDownButtonOnFocusBackColorGets or sets the colour the spin buttons are filled with while they are hot: while the pointer is over the control, while it has the focus, and at all times while ShowBorderAlways is set.
Methods
CreateHandleCreates the control's window.
OnFontChangedRaises the Control.FontChanged event, then fits the spin button to the new font.
OnGotFocusRaises the Control.GotFocus event and draws the border and buttons in their hot colours.
OnLayoutRaises the Control.Layout event, then fits the spin button to the control's height and font.
OnLostFocusRaises the Control.LostFocus event and, unless ShowBorderAlways is set, returns the border and buttons to their resting colours.
OnSystemColorsChangedRaises the Control.SystemColorsChanged event when the Windows colour scheme changes.
WndProcProcesses the window's messages, drawing the flat border while DrawStyleIsFlat is set.

Constructors

BinaryNumericUpDown

public BinaryNumericUpDown()

Initialises the control with flat drawing on, the border shown at all times and the button colours taken from the Windows colour scheme.

Properties

BorderColor

public Color BorderColor

Gets or sets the colour of the control's one-pixel border while it is hot, and of the outline round hot spin buttons.

Value
The default is SystemColors.Highlight.
Remarks

The border is hot while the pointer is over the control, while it has the focus, or always when ShowBorderAlways is set. At rest it is drawn in Control.BackColor, so it disappears.

BorderStyle

public new BorderStyle BorderStyle

Gets or sets the border style, which this control keeps at BorderStyle.Fixed3D.

Value
Always BorderStyle.Fixed3D: any other value is ignored. The flat drawing paints over the 3D border, so DrawStyleIsFlat is the setting that changes the look.

DrawStyleIsFlat

public bool DrawStyleIsFlat

Gets or sets whether the control is drawn flat, with the colours set on it, or with the standard 3D look.

Value
true for the flat look. The default is true.
Default
true
Remarks

While it is false none of the colour properties is used and the control looks exactly like NumericUpDown. Changing it re-creates the control's window.

ShowBorderAlways

public bool ShowBorderAlways

Gets or sets whether the border and spin buttons are shown in their hot colours at all times, rather than only while the pointer is over the control or it has the focus.

Value
true to show them always. The default is true.
Remarks

While it is true the border is drawn in BorderColor and the buttons in UpDownButtonOnFocusBackColor whatever the pointer does, so UpDownButtonNormalBackColor is not seen. Set it to false for a control that rests with a border the colour of its background and lights up on hover or focus – the usual choice for a dense form or a toolbar.

A disabled control always draws its border in SystemColors.ControlDark.

See also

UpDownArrowPressedBackColor

public Color UpDownArrowPressedBackColor

Gets or sets the colour a spin button is filled with while it is held down.

Value
The default is a strong shade of the Windows highlight colour, which follows the colour scheme. Set Color.Empty to return to it.
Remarks

Only the button under the pointer – up or down – takes this colour; the other keeps its hot colour.

See also

UpDownArrowsColor

public Color UpDownArrowsColor

Gets or sets the colour of the up and down arrows on the spin buttons.

Value
The default is SystemColors.ControlText.
Remarks

The arrows keep this colour when the control is disabled.

UpDownButtonNormalBackColor

public Color UpDownButtonNormalBackColor

Gets or sets the colour the spin buttons are filled with at rest – when the pointer is elsewhere and the control does not have the focus.

Value
The default is SystemColors.Control, following the colour scheme. Set Color.Empty to return to it.
Remarks

Seen only while ShowBorderAlways is false, and on a disabled control.

UpDownButtonOnFocusBackColor

public Color UpDownButtonOnFocusBackColor

Gets or sets the colour the spin buttons are filled with while they are hot: while the pointer is over the control, while it has the focus, and at all times while ShowBorderAlways is set.

Value
The default is a pale tint of the Windows highlight colour (about a quarter highlight on the window colour), which follows the colour scheme. Set Color.Empty to return to it.
Remarks

Hot buttons are also outlined in BorderColor.

Example
spinner.UpDownButtonNormalBackColor = Color.WhiteSmoke;
spinner.UpDownButtonOnFocusBackColor = Color.AliceBlue;
spinner.UpDownArrowPressedBackColor = Color.LightSteelBlue;
spinner.ShowBorderAlways = false;   // so the resting colour is seen

Methods

CreateHandle

protected override void CreateHandle()

Creates the control's window.

Remarks

When the window is being created again – after DrawStyleIsFlat changes, for example – the control takes over the drawing of the new text box and spin button windows at the next paint.

OnFontChanged

protected override void OnFontChanged(EventArgs e)

Raises the Control.FontChanged event, then fits the spin button to the new font.

Parameters
e
The event data.
See also

OnGotFocus

protected override void OnGotFocus(EventArgs e)

Raises the Control.GotFocus event and draws the border and buttons in their hot colours.

Parameters
e
The event data.

OnLayout

protected override void OnLayout(LayoutEventArgs e)

Raises the Control.Layout event, then fits the spin button to the control's height and font.

Parameters
e
The event data.
Remarks

The spin button is as wide as a vertical scroll bar or 1.1 times the font's height, whichever is wider, but never more than a third of the control's width; the text box takes the rest. It moves to the left side when Control.RightToLeft is Yes.

OnLostFocus

protected override void OnLostFocus(EventArgs e)

Raises the Control.LostFocus event and, unless ShowBorderAlways is set, returns the border and buttons to their resting colours.

Parameters
e
The event data.

OnSystemColorsChanged

protected override void OnSystemColorsChanged(EventArgs e)

Raises the Control.SystemColorsChanged event when the Windows colour scheme changes.

Parameters
e
The event data.
Remarks

Button colours that have not been set are worked out from the system colours each time they are drawn, so they follow the new scheme.

WndProc

protected override void WndProc(ref Message m)

Processes the window's messages, drawing the flat border while DrawStyleIsFlat is set.

Parameters
m
The message to process.
Remarks

An override must call the base method for every message it does not handle completely, or the border and buttons are not drawn.