BinaryColorPickerDropDown
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 | |
|---|---|
BinaryColorPickerDropDown | Initialises a hidden colour window, with white selected. |
| Properties | |
CustomColorRectangleBorderStyle | Gets or sets the 3-D edge drawn round each cell of the Custom palette. |
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. |
| Methods | |
Dispose | Releases the resources held by the window. |
OnDeactivate | Raises the Form.Deactivate event and hides the window, as a click elsewhere in the
application does. |
OnLoad | Sizes the window and its palette for the current display, then raises the
Form.Load event. |
OnPaint | Raises the Control.Paint event and draws the window's one-pixel black outline. |
ScaleCore | Does nothing: the window sizes itself for the display each time it is shown, so the framework's own scaling is switched off. |
Show | Shows the window with its top-left corner at the given point on the screen, sized for the display it appears on. |
WndProc | 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. |
| Events | |
BinaryColorPickerSelectedColorChanged | Occurs when the user chooses a colour in the window: clicks a palette cell or a list entry, or defines a custom colour. |
Constructors
BinaryColorPickerDropDown
Initialises a hidden colour window, with white selected.
Properties
CustomColorRectangleBorderStyle
Gets or sets the 3-D edge drawn round each cell of the Custom palette.
- Value
- One of the
Border3DStylevalues. The default isSunken.
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
Releases the resources held by the window.
Parameters
disposingtruewhen called fromDispose;falsewhen called from the finaliser.
OnDeactivate
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
Sizes the window and its palette for the current display, then raises the
Form.Load event.
Parameters
e- The data for the event.
OnPaint
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
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
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
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
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.