BinaryOfficeColorPicker
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 | |
|---|---|
BinaryOfficeColorPicker | Initialises the palette with tool tips on, the alpha and blend panel showing, and no colour selected. |
| Properties | |
AlphaValue | Gets or sets a stored alpha value, from 0 to 255. |
BlendTargetColor | Gets or sets the colour the chosen colour is mixed with, shown in the "Blend with color" swatch. |
BorderColor | Gets or sets the colour of the line round the palette. |
EnableSettingAlphaValue | Gets or sets whether the alpha slider and the "Blend with color" swatch are shown at the bottom of the picker. |
HeadingBackColor | Gets or sets the background of the "Theme Colors" and "Standard Colors" headings, the "More colors..." strip and the alpha panel. |
HeadingForeColor | Gets or sets the colour of the heading text and the labels in the "More colors..." strip and the alpha panel. |
SelectedColorRectangleBorder | Gets or sets the colour of the frame drawn round the swatch the user clicked. |
ShowHSBInToolTip | Gets or sets whether the swatch tool tips add the colour's hue, saturation and brightness. |
ShowToolTip | Gets or sets whether pointing at a swatch shows its colour's name, or its RGB values. |
UserSelectedColor | Gets or sets the colour the user chose, before any blending, shown in the preview swatch. |
| Methods | |
OnDoubleClick | Raises the Control.DoubleClick event, then
BinaryColorPickerSelectedColorChanged with the chosen colour at
AlphaValue. |
| Events | |
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. |
SelectionCommitted | Occurs when the user has finished choosing: a swatch is double-clicked, or the preview swatch is clicked. |
Constructors
BinaryOfficeColorPicker
Initialises the palette with tool tips on, the alpha and blend panel showing, and no colour selected.
Properties
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
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.Emptyuntil 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
Gets or sets the colour of the line round the palette.
- Value
- The border colour. The getter returns
SystemColors.WindowTextuntil the property is set, while the line is drawn in blue-grey, RGB (133, 155, 183).
EnableSettingAlphaValue
Gets or sets whether the alpha slider and the "Blend with color" swatch are shown at the bottom of the picker.
- Value
trueto show them;falseto hide them. The value reported by default isfalse, 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
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
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
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
Gets or sets whether the swatch tool tips add the colour's hue, saturation and brightness.
- Value
trueto add them; the default isfalse.
Remarks
Read when the picker loads, so set it before the picker is first shown.
ShowToolTip
Gets or sets whether pointing at a swatch shows its colour's name, or its RGB values.
- Value
trueto show tool tips; the default istrue.
Remarks
Read when the picker loads, so set it before the picker is first shown.
See also
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.Emptyuntil 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
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
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
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.