The ColorPicker WinForms Control


Although the .NET framework provides quite a rich collection of UI controls and components for WinForms development, there is one particular control that's been missing. I'm talking about a color-picker control with drop-down color selection capabilities, just like the one used within the Visual Studio .NET property browser for editing Color-typed properties. Based on these observations, I've decided to implement a ColorPicker control with the following features:
  • The control should look and act like a button.
  • The button should be colored with the currently selected color and, optionally, it should display the currently selected color's name.
  • Clicking the button should drop-down the built-in WinForms color selector and the control should change its appearance to a "pushed down" look.

The main design goals were implementation simplicity and the ability to reuse the control in either binary, or in source code form (VB.NET source code; just include the ColorPicker.vb file into your project and you're done).

The demo application

The following is the important part of the ColorPicker's public contract (the semantics should be self-explanatory):

Namespace LaMarvin.Windows.Forms

Public Class ColorPicker Inherits Control
    Public Event ColorChanged As EventHandler
    Public Property Color() As Color

For those of you in a hurry, you can download the control along with an accompanying demo application here.

But wait!

If you want to learn something about the inner workings of the WinForms design-time support, as well as some undocumented .NET framework tricks, please, read on.

You might also like...


About the author

Palo Mraz

Palo Mraz United States

I live in Slovakia with my wife, two sons (fulltime), one daughter (occasionally) and a dog. I've been doing Microsoft Windows development since 1988; primarily in VB. I'm a big fan of the MS .N...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill