HypernovaDesktop Components · docs
Binarymission
WinForms › Office2007 Color Picker

Office2007 Color Picker

.NET Framework 4.8.NET 6 / 8 / 10v3.0.0WinForms

A combo box for choosing a colour from an Office-style palette: it shows the chosen colour as a swatch with its RGB values or name, and drops down a BinaryOfficeColorPicker with theme colours, standard colours, "More colors..." and optional alpha blending.

5public types
81public members
1namespaces

Assembly

AssemblyBinarymission.WinForms.Controls.OfficeColorPicker.dll
Root namespaceBinarymission.WinForms.Controls.ColorPickers
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10

Overview

What it is for

Use it wherever users pick a colour and expect the Office look – text and fill colours in an editor, a category colour in a planner, a series colour in a report designer.

How it works

  • A click on the control opens the palette just below it; a second click on the control closes it.
  • A single click on a swatch updates SelectedColor straight away and raises SelectedColorChanged, leaving the palette open so the user can try colours. A double-click on a swatch, or a click on the preview swatch, commits the choice and closes the palette.
  • With EnableSettingAlphaValue, the palette also offers an alpha slider and a blend colour; the colour reported is the chosen colour mixed with BlendTargetColor.

The palette's appearance is set through this control – HeadingBackColor, HeadingForeColor, BorderColor, CustomColorForRectangleBorder, ShowToolTip. The closed control is drawn flat, its border in CustomControlBorderColor while it has the focus or the pointer. Right-to-left layout is not supported.

Note

After the palette is closed by a click elsewhere, the next click on the control does not open it; the click after that does.

Getting started

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

public class CategoryForm : Form
{
    private readonly BinaryOfficeColorPickerComboBox categoryColour;
    private readonly Label preview;

    public CategoryForm()
    {
        Text = "Edit category";
        ClientSize = new Size(320, 90);

        categoryColour = new BinaryOfficeColorPickerComboBox
        {
            Location = new Point(12, 12),
            Width = 180,
            ShowColorNameIfKnownColor = true,
            HeadingBackColor = Color.Gainsboro,
            ShowHSBInToolTip = true
        };
        categoryColour.SelectedColorChanged += CategoryColour_SelectedColorChanged;

        preview = new Label { Text = "Client meetings", Location = new Point(206, 15), AutoSize = true };

        Controls.Add(categoryColour);
        Controls.Add(preview);
    }

    private void CategoryColour_SelectedColorChanged(object sender, BinaryColorPickerExtendedEventArgs e)
    {
        // Read the property: e is null when the colour is set in code before the user has chosen one.
        preview.BackColor = categoryColour.SelectedColor;
    }
}

API reference

Binarymission.WinForms.Controls.ColorPickers

class BinaryColorPickerExtendedEventArgsProvides data for the Office-style colour picker's events: the colour to use, and the alpha value and blend colour it was mixed from.
class BinaryOfficeColorPickerAn 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.
class BinaryOfficeColorPickerComboBoxA combo box for choosing a colour from an Office-style palette: it shows the chosen colour as a swatch with its RGB values or name, and drops down a BinaryOfficeColorPicker with theme colours, standard colours, "More colors..." and optional alpha blending.
class BinaryOfficeColorPickerComboBoxDesignerActionListThe smart-tag panel shown for a BinaryOfficeColorPickerComboBox on the Windows Forms design surface, offering the control's colours and the drop-down palette's settings.
class BinaryOfficeColorPickerDesignerActionListThe smart-tag panel shown for a BinaryOfficeColorPicker on the Windows Forms design surface, offering its heading colours, border colours and the alpha panel switch.