HypernovaDesktop Components · docs
Binarymission
WinForms › Office2007 Color Picker › BinaryOfficeColorPicker

BinaryOfficeColorPicker

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

An Office-style colour palette – theme colours in shades, a row of standard colours and a "More colors..." button – that can also mix the chosen colour with a second colour. It is the panel BinaryOfficeColorPickerComboBox drops down, and can be placed on a form by itself.

public partial class BinaryOfficeColorPicker : UserControl

Inherits from / implements: UserControl

Remarks

What it is for

Place it directly on a form, a tool window or a ToolStripDropDown when the palette should be on show rather than behind a combo box – a formatting pane, say. For a compact field, use BinaryOfficeColorPickerComboBox.

The parts

  • Theme Colors and Standard Colors – swatches with tool tips giving each colour's name or RGB values (ShowToolTip, ShowHSBInToolTip).
  • More colors... – opens the Windows colour dialog for any colour, and shows the current choice in a preview swatch.
  • Alpha and blend – a slider and a number box from 0 to 255, and a "Blend with color" swatch. The colour reported is the chosen colour mixed with the blend colour: at 255 it is the chosen colour unchanged.

The two events

  • BinaryColorPickerSelectedColorChanged – the choice moved: a swatch was clicked, the alpha value or blend colour changed, or a colour dialog closed.
  • SelectionCommitted – the user has finished: a swatch was double-clicked, or the preview swatch was clicked. Close a pop-up here, not on the first event.

Both carry a BinaryColorPickerExtendedEventArgs whose BinaryColorPickerExtendedEventArgs.UserSelectedColor is the colour to use.

Examples

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

public class HighlightPane : UserControl
{
    private readonly Label sample = new Label { Text = "Overdue invoice", AutoSize = true, Location = new Point(190, 12) };
    private Color overdueHighlight = Color.Empty;

    public HighlightPane()
    {
        var palette = new BinaryOfficeColorPicker
        {
            Location = new Point(8, 8),
            HeadingBackColor = Color.Gainsboro,
            ShowHSBInToolTip = true
        };

        // Follow the choice as it moves, and keep it once the user commits.
        palette.BinaryColorPickerSelectedColorChanged += (sender, e) => sample.BackColor = e.UserSelectedColor;
        palette.SelectionCommitted += (sender, e) => overdueHighlight = e.UserSelectedColor;

        Controls.Add(palette);
        Controls.Add(sample);
    }
}

See also

Members at a glance

Constructors
BinaryOfficeColorPickerInitialises the palette with tool tips on, the alpha and blend panel showing, and no colour selected.
Properties
AlphaValueGets or sets a stored alpha value, from 0 to 255.
BlendTargetColorGets or sets the colour the chosen colour is mixed with, shown in the "Blend with color" swatch.
BorderColorGets or sets the colour of the line round the palette.
EnableSettingAlphaValueGets or sets whether the alpha slider and the "Blend with color" swatch are shown at the bottom of the picker.
HeadingBackColorGets or sets the background of the "Theme Colors" and "Standard Colors" headings, the "More colors..." strip and the alpha panel.
HeadingForeColorGets or sets the colour of the heading text and the labels in the "More colors..." strip and the alpha panel.
SelectedColorRectangleBorderGets or sets the colour of the frame drawn round the swatch the user clicked.
ShowHSBInToolTipGets or sets whether the swatch tool tips add the colour's hue, saturation and brightness.
ShowToolTipGets or sets whether pointing at a swatch shows its colour's name, or its RGB values.
UserSelectedColorGets or sets the colour the user chose, before any blending, shown in the preview swatch.
Methods
OnDoubleClickRaises the Control.DoubleClick event, then BinaryColorPickerSelectedColorChanged with the chosen colour at AlphaValue.
Events
BinaryColorPickerSelectedColorChangedOccurs when the user's choice changes: a swatch is clicked, the alpha value or the blend colour changes, or a colour dialog is closed.
SelectionCommittedOccurs when the user has finished choosing: a swatch is double-clicked, or the preview swatch is clicked.

Constructors

BinaryOfficeColorPicker

public BinaryOfficeColorPicker() : base()

Initialises the palette with tool tips on, the alpha and blend panel showing, and no colour selected.

Properties

AlphaValue

public int AlphaValue

Gets or sets a stored alpha value, from 0 to 255.

Value
The default is 255.
Remarks

Setting it does not move the alpha slider, and the colours the events report are mixed at the slider's value, which the user sets. The stored value is used only when the picker raises its own Control.DoubleClick event (see BinaryColorPickerSelectedColorChanged).

BlendTargetColor

public Color BlendTargetColor

Gets or sets the colour the chosen colour is mixed with, shown in the "Blend with color" swatch.

Value
The blend colour. The getter returns Color.Empty until the property is set, though the swatch starts olive green, RGB (106, 130, 61).
Remarks

The mix is made at the alpha slider's value; at 255, the default, the blend colour has no effect. The user can also choose the blend colour with the button beside the swatch.

BorderColor

public Color BorderColor

Gets or sets the colour of the line round the palette.

Value
The border colour. The getter returns SystemColors.WindowText until the property is set, while the line is drawn in blue-grey, RGB (133, 155, 183).

EnableSettingAlphaValue

public bool EnableSettingAlphaValue

Gets or sets whether the alpha slider and the "Blend with color" swatch are shown at the bottom of the picker.

Value
true to show them; false to hide them. The value reported by default is false, although a new picker shows the panel until the property is set.
Remarks

Showing or hiding the panel changes the picker's height by the panel's height.

HeadingBackColor

public Color HeadingBackColor

Gets or sets the background of the "Theme Colors" and "Standard Colors" headings, the "More colors..." strip and the alpha panel.

Value
The heading colour. The default is a pale blue-grey, RGB (204, 219, 230).

HeadingForeColor

public Color HeadingForeColor

Gets or sets the colour of the heading text and the labels in the "More colors..." strip and the alpha panel.

Value
The text colour. The default is SystemColors.WindowText.

SelectedColorRectangleBorder

public Color SelectedColorRectangleBorder

Gets or sets the colour of the frame drawn round the swatch the user clicked.

Value
The frame colour. The default is SystemColors.WindowText.
Remarks

Applied the next time a swatch is clicked.

ShowHSBInToolTip

public bool ShowHSBInToolTip

Gets or sets whether the swatch tool tips add the colour's hue, saturation and brightness.

Value
true to add them; the default is false.
Remarks

Read when the picker loads, so set it before the picker is first shown.

ShowToolTip

public bool ShowToolTip

Gets or sets whether pointing at a swatch shows its colour's name, or its RGB values.

Value
true to show tool tips; the default is true.
Remarks

Read when the picker loads, so set it before the picker is first shown.

See also

UserSelectedColor

public Color UserSelectedColor

Gets or sets the colour the user chose, before any blending, shown in the preview swatch.

Value
The chosen colour. The getter returns Color.Empty until a colour is chosen or set.
Remarks

Set it before showing the picker to start from the colour already in use. Setting it does not raise an event.

Methods

OnDoubleClick

protected override void OnDoubleClick(EventArgs e)

Raises the Control.DoubleClick event, then BinaryColorPickerSelectedColorChanged with the chosen colour at AlphaValue.

Parameters
e
The data for the event.
Remarks

The swatches and panels cover the picker, so this runs only for a double-click that reaches the picker itself; a double-click on a swatch raises SelectionCommitted instead.

Events

BinaryColorPickerSelectedColorChanged

public event EventHandler<BinaryColorPickerExtendedEventArgs> BinaryColorPickerSelectedColorChanged

Occurs when the user's choice changes: a swatch is clicked, the alpha value or the blend colour changes, or a colour dialog is closed.

Remarks

BinaryColorPickerExtendedEventArgs.UserSelectedColor is the colour to use, already mixed with the blend colour. The event is raised when a colour dialog is cancelled too, with the choice unchanged.

It is also raised after the picker's own Control.DoubleClick event; the data then carries the chosen colour with its alpha channel set to AlphaValue, and no blend colour.

See also

SelectionCommitted

public event EventHandler<BinaryColorPickerExtendedEventArgs> SelectionCommitted

Occurs when the user has finished choosing: a swatch is double-clicked, or the preview swatch is clicked.

Remarks

This is the event to close a pop-up on. BinaryColorPickerExtendedEventArgs.UserSelectedColor is the colour to use.

See also