Library tutorials & articles

The ColorPicker WinForms Control

Introduction

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.

Comments

  1. 12 Sep 2007 at 22:39

    Excellent control.

    I have used it in win forms and it works quite nicly.

    only one small issue. when you press the button and 3 tabbed popup drops down. if you click anywhere where out side that color selection, the whole form gets minimized.

    for example if i have the button on the form and i press the button the color selection comes up. at this point instead of picking the color if i click any where on the form, the whole form goes to the backgroud (some other window comes in front.)

    if you have a quick fix or a work around that will be great.

    once again, Excellent work

    Adeel

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of The ColorPicker WinForms Control.

Leave a comment

Sign in or Join us (it's free).

Palo Mraz 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 .NET ...

Related podcasts

  • xpert to Expert: Inside Concurrent Basic (CB)

    "Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...

Want to stay in touch with what's going on? Follow us on twitter!