Back at the start of the new millennium, I had a publishing
agreement with another company to publish our components under
their branding. The first of these components was the
ColorPicker ActiveX control. Roll on 13 years later and that
publishing agreement is long expired, ActiveX is dead, and yet
here I am again writing a color picker control. Except this time
losing money rather than making it. There's probably a life
lesson buried in there somewhere.
All of our current products ask for a color at least once
(mostly buried in an options dialog), and some of the prototype
products we are working on ask for more. Currently, we just wrap
around the System.Drawing.Design.ColorEditor class, which
overtime has identified a few problems:
Keyboard support is iffy (this is more to do with how it's
implemented at our end I suspect)
You can't choose alpha channels, or enter custom values
The dependency on System.Design prevents us from targeting
the Client Profile, and indeed will cause a crash if deployed
to a system with only the Client Profile installed
The other option briefly considered was just to replace with the
standard color common dialog. But this dialog looks and operates
the same as it did back in Windows 3, and while that is pretty
good from a consistent UI standpoint, it does mean it hasn't
kept up with changing times - such as entering colors as hex
values. I took a look at some other third party libraries but
none of them were flexible enough for what I wanted.
In the end I went with writing my own set of C# based color
picker controls which we're providing here as open source - we
hope you find them useful. As there's quite a lot of code, I'm
not going to describe them line by line as I've done in the
past, but just provide an overview of each component.
This control displays a grid of colors, and supports both a
primary palette, and a custom color palette. Several properties
are available for configuring the appearing of the control, and
there are behaviour options too, such as built in editing of
This control displays a radial wheel of colors and allows
selection from any point in the wheel. Not much in the way of
customisation for this control!
A bunch of controls (inheriting from a single base) that allow
selection of values via a colourful bar. Similar to the
TrackBar control you have a few options for specifying the
drag handle's position and bar orientation.
This control allows you enter/select a color using RGB/HSL or
This control allows the user to pick a color from any pixel
displayed on the screen.
This form puts together the previous controls in a ready to use
This is a non-GUI component that you can drop onto a form, and
bind to other controls in this library. When the Color
property of one control changes, it is reflected in the others
without having to lift a finger. Useful if you're creating
composite displays from multiple controls.
The ColorGrid control has Colors and CustomColors
properties which return a ColorCollection. These two
properties make it easier as a developer to keep separate a
primary palette whilst having the flexibility of custom colors,
although it does complicate the control's internal logic a bit!
The grid will automatically populate custom colors if you try
and set the control's Color to a value not currently defined.
As well as manually populating ColorCollection instances, you
can also load in external palette files. Paint.NET and the age
old JASC 1.0 formats are currently supported.
All GUI components, with the exception of the
ScreenColorPicker include full keyboard/focus support. Many
controls support SmallChange and LargeChange properties
which influence how navigation keys are processed. Although in
the case of the ColorWheel it's not really a bonus... but
that's what the ColorEditor control is best suited for!
XML documentation comments are incomplete
The ColorEditorManager control currently allows you to bind
to the LightnessColorSlider control, but doesn't fully
support it yet
The founder of Cyotek, Richard enjoys creating new blog content for the site. Much more though, he likes to develop programs, and can often found writing reams of code. A long term gamer, he has aspirations in one day creating an epic video game - but until that time comes, he is mostly content with adding new bugs to WebCopy and the other Cyotek products.
The `ColorGrid` control is a fairly useful control for selecting from a predefined list of colours. However, it can take up quite a bit of screen real estate depending on how many colours it contains. This article describes how you can host a `ColorGrid` in a standard `ToolStrip` control, providing access to both the `ColorGrid` and the `ColorPickerDialog`, with some custom painting to show the active colour on the button to round it off.
The [ColorPicker Controls](https://github.com/cyotek/Cyotek.Windows.Forms.ColorPicker) have been updated to version 126.96.36.199.
This is a fairly substantial update, with quite a few bug fixes and enhancements to the code. I'll also briefly discuss plans for future updates to the library.