Skip to content

cyotek/Cyotek.Windows.Forms.ColorPicker

Repository files navigation

Icon Cyotek Color Picker Controls for Windows Forms

Build status NuGet

The Cyotek.Windows.Forms.ColorPickers library contains a series of custom controls and utility classes for Windows Forms applications that work with colours. Controls are available to allow colour selection via a HSL ColorWheel, a ColorGrid with many customisation options, a ColorEditor for entering colours via RGB or HSL, and a ScreenColorPicker for capturing colours from running applications.

Color palettes can be loaded and saved in a number of different formats, including Adobe PhotoShop Color Swatch files, JASC Palettes, Gimp Palettes and more (see Color Palettes and External Palette Files below).

For more information on these controls, see the articles tagged with colorpicker at cyotek.com.

Getting the library

The easiest way of obtaining the library is via NuGet.

Install-Package Cyotek.Windows.Forms.ColorPicker

If you don't use NuGet, pre-compiled binaries can be obtained from the GitHub Releases page.

Of course, you can always grab the source and build it yourself!

Controls

There are three primary controls (ColorGrid, ColorWheel and ColorEditor), along with 5 utility controls (ScreenColorPicker, RgbaColorSlider, HueColorSlider, LightnessColorSlider and SaturationColorSlider), a management component (ColorEditorManager) and one dialog (ColorPickerDialog). Combined together, these provide a decent array of tools for colour selection.

ColorGrid Control

ColorGrid control demonstration

This control displays a grid of colours, and supports both a primary palette, and a custom colour palette. Several properties are available for configuring the appearing of the control, and there are behaviour options too, such as built in editing of colours and support for automatically adding new colours not in the primary palette.

ColorWheel Control

ColorWheel control demonstration

This control displays a radial wheel of RGB colours and allows selection from any point in the wheel. The ShowAngleArrow, ShowCenterLines and ShowSaturationRing properties can be used to display useful adornments, while the Lightness and Alpha properties can be used to compose the final colour while not being directly editable on the wheel.

The SecondaryColors and SecondarySelectionSize properties allow you to display additional colours on the wheel, for example for showing relationships.

ColorSlider Controls

ColorSlider controls demonstration

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. You can also customise the fill and outline colour, or replace it completely with a custom image.

ColorEditor Control

ColorEditor control demonstration

This control allows the editing of a RGB or HSL colour via a standard interface. You can also enter colours via 6 or 8 character hexadecimal notation, or choose from named web and system colors.

Use of the alpha channel can be configured via the ShowAlphaChannel and PreserveAlphaChannel properties. The ShowHex, ShowHsl and ShowRgb properties can be used to show or hide groups of editors.

Alternatively, the NubSize, NubColor and NubOutlineColor properties can be used to customise the appearance of the sliders.

ScreenColorPicker Control

ScreenColorPicker control demonstration

This control allows the user to pick a colour from any pixel displayed on the screen. The user can either trigger the operation by clicking and dragging the control, or it can be done programmatically via the CaptureMouse method, allowing selections to be triggered via other actions, for example a hot key. The Zoom property can be used set the grid size of the preview.

ColorPickerDialog Form

ColorPickerDialog form demonstration

This form puts together the previous controls in a ready to use dialog.

Custom colours are supported via the CustomColors property, and users can also load or save external palette files into these. You can use the ShowLoad and ShowSave properties to enable or disable this, and the CustomColorsLoading and CustomColorsSavingevents to override the built-in behaviour and provide your own logic.

ColorEditorManager

ColorEditorManager compnent demonstration

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.

Color Palettes and External Palette Files

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 colours, although it does complicate the control's internal logic a bit! The grid will automatically populate custom colours 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. The following palette formats are supported:

  • Adobe Color Table (*.act)
  • Adobe PhotoShop Color Swatch (*.aco)
  • GIMP (*.gpl)
  • Deluxe Paint (*.bbm; *.lbm) [read only]
  • JASC (*.pal)
  • Paint.NET (*.txt)
  • Raw RGB Triplets (*.pal)

With the exception of the ILBM image format, all other formats can be exported as well as imported.

Additional palette serializers can be easily created by adding a class which implements IPaletteSerializer. The ColorPickerDialog (or any custom code using PaletteSerializer static methods) will automatically detect and make available custom palettes via reflection.

Keyboard Support

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!

Requirements

.NET Framework 3.5 or later.

Pre-built binaries are available via a signed NuGet package containing the following targets.

  • .NET 3.5
  • .NET 4.0
  • .NET 4.5.2
  • .NET 4.6.2
  • .NET 4.7.2
  • .NET 4.8
  • .NET 5.0

Contributing to this code

Contributions accepted!

Alternatively, if you make use of this software and it saves you some time, donations are welcome.

PayPal Donation

By Me a Coffee Donation

Known Issues

  • XML documentation comments are incomplete

Related Reading

Acknowledgements