HypernovaDesktop Components · docs
Binarymission
WinForms › Color Picker › BinaryColorPickerDropDown

BinaryColorPickerDropDown

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

The 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.

public class BinaryColorPickerDropDown : System.Windows.Forms.Form

Inherits from / implements: System.Windows.Forms.Form

Remarks

What it is for

Use it directly when a colour should be picked from a button, a toolbar or a grid cell rather than a combo box. Call Show() with a point in screen coordinates and handle BinaryColorPickerSelectedColorChanged.

The three tabs

  • Custom – an 8 x 8 palette of cells 20 logical pixels square: six shades of each of eight hues, over two rows of white cells. Right-clicking a cell in the two bottom rows opens a colour dialog; the colour chosen there replaces the cell's colour and is selected, and the window stays open. A left click selects a cell's colour and closes the window.
  • Web – the named web colours, from Transparent and Black to YellowGreen.
  • System – the Windows system colours, such as Control and WindowText.

The window opens on the tab holding SelectedColor: the System or Web tab for a named colour, the Custom tab for any other. It closes when a colour is chosen, when the user clicks anywhere outside it, or when it loses activation.

The window has no border of its own beyond a one-pixel black line, does not appear in the task bar, and sizes itself for the display it opens on.

Examples

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

public class CategoryEditor : UserControl
{
    private readonly Button colourButton = new Button { Text = "Category colour", Width = 140 };
    private readonly BinaryColorPickerDropDown colourWindow = new BinaryColorPickerDropDown();

    public CategoryEditor()
    {
        Controls.Add(colourButton);

        colourWindow.BinaryColorPickerSelectedColorChanged += (sender, e) =>
            colourButton.BackColor = colourWindow.SelectedColor;

        colourButton.Click += (sender, e) =>
        {
            colourWindow.SelectedColor = colourButton.BackColor;
            // Open just below the button, in screen coordinates.
            colourWindow.Show(colourButton.PointToScreen(new Point(0, colourButton.Height)));
        };
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            colourWindow.Dispose();
        }

        base.Dispose(disposing);
    }
}

Members at a glance

Constructors
BinaryColorPickerDropDownInitialises a hidden colour window, with white selected.
Properties
CustomColorRectangleBorderStyleGets or sets the 3-D edge drawn round each cell of the Custom palette.
SelectedColorGets or sets the colour selected in the window – the one the user last chose, or one set before showing the window so that it opens on the right tab.
Methods
DisposeReleases the resources held by the window.
OnDeactivateRaises the Form.Deactivate event and hides the window, as a click elsewhere in the application does.
OnLoadSizes the window and its palette for the current display, then raises the Form.Load event.
OnPaintRaises the Control.Paint event and draws the window's one-pixel black outline.
ScaleCoreDoes nothing: the window sizes itself for the display each time it is shown, so the framework's own scaling is switched off.
ShowShows the window with its top-left corner at the given point on the screen, sized for the display it appears on.
WndProcProcesses the window's messages. After the window paints, it watches the message queue until it is dismissed, closing itself when a mouse button is pressed outside it and ignoring pointer movement over other windows.
Events
BinaryColorPickerSelectedColorChangedOccurs when the user chooses a colour in the window: clicks a palette cell or a list entry, or defines a custom colour.

Constructors

BinaryColorPickerDropDown

public BinaryColorPickerDropDown()

Initialises a hidden colour window, with white selected.

Properties

CustomColorRectangleBorderStyle

public Border3DStyle CustomColorRectangleBorderStyle

Gets or sets the 3-D edge drawn round each cell of the Custom palette.

Value
One of the Border3DStyle values. The default is Sunken.

SelectedColor

public Color SelectedColor

Gets or sets the colour selected in the window – the one the user last chose, or one set before showing the window so that it opens on the right tab.

Value
The selected colour. The default is Color.White.
Remarks

Setting it does not raise BinaryColorPickerSelectedColorChanged. Colours from the Web and System tabs are named colours, made with Color.FromName.

Methods

Dispose

protected override void Dispose(bool disposing)

Releases the resources held by the window.

Parameters
disposing
true when called from Dispose; false when called from the finaliser.

OnDeactivate

protected override void OnDeactivate(EventArgs e)

Raises the Form.Deactivate event and hides the window, as a click elsewhere in the application does.

Parameters
e
The data for the event.

OnLoad

protected override void OnLoad(EventArgs e)

Sizes the window and its palette for the current display, then raises the Form.Load event.

Parameters
e
The data for the event.

OnPaint

protected override void OnPaint(PaintEventArgs pe)

Raises the Control.Paint event and draws the window's one-pixel black outline.

Parameters
pe
The graphics surface and the area to paint.

ScaleCore

protected override void ScaleCore(float dx, float dy)

Does nothing: the window sizes itself for the display each time it is shown, so the framework's own scaling is switched off.

Parameters
dx
The horizontal scaling factor, ignored.
dy
The vertical scaling factor, ignored.

Show

public void Show(Point targetPostion)

Shows the window with its top-left corner at the given point on the screen, sized for the display it appears on.

Parameters
targetPostion
The top-left corner, in screen coordinates – for example someControl.PointToScreen(new Point(0, someControl.Height)) to open below a control.
Remarks

The window is shown modelessly and the method returns at once. The window is hidden, not closed, when it is dismissed, so the same instance can be shown again; dispose of it when the owner is disposed.

WndProc

protected override void WndProc(ref Message m)

Processes the window's messages. After the window paints, it watches the message queue until it is dismissed, closing itself when a mouse button is pressed outside it and ignoring pointer movement over other windows.

Parameters
m
The message to process.
Remarks

While the window is open, the paint message does not return until the window is closed; other messages are still dispatched meanwhile.

Events

BinaryColorPickerSelectedColorChanged

public event EventHandler BinaryColorPickerSelectedColorChanged

Occurs when the user chooses a colour in the window: clicks a palette cell or a list entry, or defines a custom colour.

Remarks

Read SelectedColor in the handler. Setting SelectedColor in code does not raise the event.