HypernovaDesktop Components · docs
Binarymission
WinForms › Color Picker

Color Picker

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

A combo box for choosing a colour: it shows the chosen colour as a swatch with its RGB values or name, and opens a three-tab colour window – a custom palette, the web colours and the Windows system colours – in place of a list.

2public types
43public members
1namespaces

Assembly

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

Overview

What it is for

Use it on settings and design forms wherever the user picks a colour – a chart series, a calendar category, a highlight for overdue invoices – and a full colour dialog is too much. It looks and tabs like a drop-down list, in the style of the Visual Studio colour picker.

How it works

  • A click anywhere on the control opens the colour window below it (a BinaryColorPickerDropDown). It has three tabs: Custom, an 8 x 8 palette whose two bottom rows the user can redefine by right-clicking a cell; Web, the named web colours; and System, the Windows system colours.
  • Choosing a colour sets SelectedColor and raises SelectedColorChanged; picking a palette cell or a list entry also closes the window. A click outside the window closes it with no change.
  • The control shows the colour's red, green and blue values – "70, 130, 180" – or, with ShowColorNameIfKnownColor, its name when it has one.

Appearance

The control draws itself flat. Its border appears in CustomControlBorderColor while it has the focus or the pointer, or always with ShowBorderAlways; the drop-down button and the highlight are shades of CustomPaintingColor, mixed by the three AlphaBlendFactor properties. Right-to-left layout is not supported.

Getting started

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

public class ChartSettingsForm : Form
{
    private readonly BinaryColorPickerComboBox seriesColourPicker;
    private readonly Panel preview;

    public ChartSettingsForm()
    {
        Text = "Chart settings";
        ClientSize = new Size(320, 120);

        seriesColourPicker = new BinaryColorPickerComboBox
        {
            Location = new Point(12, 12),
            Width = 200,
            ShowColorNameIfKnownColor = true,
            CustomControlBorderColor = Color.SteelBlue,
            CustomPaintingColor = Color.SteelBlue
        };
        seriesColourPicker.SelectedColorChanged += SeriesColourPicker_SelectedColorChanged;

        preview = new Panel { Location = new Point(224, 12), Size = new Size(84, 84), BorderStyle = BorderStyle.FixedSingle };

        Controls.Add(seriesColourPicker);
        Controls.Add(preview);

        seriesColourPicker.SelectedColor = Color.SteelBlue;   // shows "SteelBlue"
    }

    private void SeriesColourPicker_SelectedColorChanged(object sender, EventArgs e)
    {
        preview.BackColor = seriesColourPicker.SelectedColor;
    }
}

API reference

Binarymission.WinForms.Controls.ColorPickers

class BinaryColorPickerComboBoxA combo box for choosing a colour: it shows the chosen colour as a swatch with its RGB values or name, and opens a three-tab colour window - a custom palette, the web colours and the Windows system colours - in place of a list.
class BinaryColorPickerDropDownThe pop-up colour window that BinaryColorPickerComboBox opens: three tabs of colours - a custom palette, the web colours and the system colours - that you can also show beside any control of your own.