Click here to Skip to main content
11,927,711 members (54,915 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked

Not just another color picker...

, 28 Jun 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An advanced color picker control for your VB.NET applications.
Screenshot - ColorPicker.jpg


This is an advanced color picker dialog box written entirely in VB.NET.


So here I am, back at it once more. I needed a color-picker control for a project I'm working on, and like most developers, I turned to my handy toolbar to see what Microsoft had for me in Visual Studio.

It wasn't long before I had a color dialog box coded and ready to use... ran my app, clicked on the select color icon, and there it was - or there something was. I guess technically, it is a color selection tool... I mean, there are colors on the dialog box and you can pick them... but (and I am being kind here) it was hideous.

So I next turned to The Code Project to see what other devs had come up with. I found several that were close to what I wanted, but the best was an older one written in C# by Danny Blanchard that mimicked the Photoshop Color Picker.

So I decided I'd take Danny's code and see if I could decipher enough of the C# to convert his control into a VB.NET control, and this is the result of that work.

Using the Code

There are two Zips for this article: ColorPickerProject.ZIP contains the source code for the dialog box, and ColorPickerDemo.ZIP contains a very simple VB.NET project that makes use of the dialog box.

Public properties
StartPosition Allows you to set the startup position for the dialog box
HeaderText This is the text displayed at the very top of the dialog box
DialogLabel This is the text that will be displayed in the label just above the color box
RGB Gets or sets the current color the dialog box is pointing at
Public event
  • ColorPickerChanged: Anytime the RGB property of the dialog box changes (either from mouse movement or keyboard entry), this event is raised. You can trap the event by adding a handler before showing the dialog box, like this:
  • Private Sub SelectColor()
        Dim OriginalColor As Color = Color.FromArgb(120, 120, 120)
        Dim cp As New ColorPicker.cp
        cp.StartPosition = FormStartPosition.CenterScreen
        cp.HeaderText = "This is a demo of the Color Picker Dialog Box"
        cp.DialogLabel = "Select Background Color"
        cp.RGB = OriginalColor
        AddHandler cp.ColorPickerChanged, AddressOf ColorChanged
        If cp.DialogResult = Windows.Forms.DialogResult.OK Then
            SampleLabel.BackColor = cp.RGB
            SampleLabel.BackColor = OriginalColor
        End If
    End Sub
    Private Sub ColorChanged(ByVal _rgb As Color, ByVal _MarkerColor As Color)
        SampleLabel.BackColor = _rgb
        SampleLabel.ForeColor = _MarkerColor
    End Sub

Points of Interest

You will probably notice from the screenshot above that I am not allowing the user to change the CMYK values. This was done for a number of reasons, starting with the most important: I don't use CMYK! LOL. Also, CMYK to RGB is not an exact science. There are far more colors in RGB than there are in CMYK, which means there are multiple RGB values for each CMYK value. Ultimately, this results in an accurate RGB to CMYK... but not the other way around.

It's also interesting to note that very few leaders in the printing industry will agree on how to convert in either direction... everyone seems to use their own conversation, resulting in close but not quite approximations... sounds funky to you? Let me explain how this is:

CMYK (Cyan, Magenta, Yellow, and Key or Black) was developed to save printers money. You see, black ink is far less expensive than colored inks. Printers learned they could reduce the amount of colored ink they use by a little, and increase the amount of black used, and the result is a very realistic approximation to a True Color image... the less colored ink you use - the more black you have to use to make up for the loss of color. Of course, you can only go so far with this before the image loses its color information. Still, you can take an RGB and calculate the CMYK value - and then you could reduce the CMY and increase the K, and still have the same RGB... and that's why you cannot say "This is the formula for converting". At best, all you can say is, "This is one of the ways you can convert".

Anyone still reading the CMYK vs. RGB debate by this point really needs to consider getting away from their PC a little more! Believe me... it's pretty boring stuff.

Nevertheless, I did find a nice conversion formula that Adobe uses, and that's what I put into this control.

HSL anyone? HSL is Hue, Saturation and Luminesc (brightness), which is yet another way of looking at colors, and is the backbone of all color conversion processes. This dialog box takes all RGB values and converts them into HSL values, then displays the results in the text boxes. You can anchor any of the HSL or RGB values by clicking on the radio button next to the appropriate value you want to anchor.


Re-uploaded the demo project - the original one wasn't pointing correctly to the local DLL, and may have cause an unresolved warning if you loaded it into Visual Studio.

The link to Danny's original control did not make it into my original article. I've re-added the link to his name mentioned in the Background section.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralType 'ColorPicker.cp' is not defined Pin
Quassi31-Jul-09 21:43
memberQuassi31-Jul-09 21:43 
GeneralRe: Type 'ColorPicker.cp' is not defined Pin
Elkay31-Jul-09 23:50
memberElkay31-Jul-09 23:50 
GeneralRe: Type 'ColorPicker.cp' is not defined Pin
Quassi13-Sep-09 0:28
memberQuassi13-Sep-09 0:28 
GeneralIn My Project Pin
eusta8-Sep-08 23:18
membereusta8-Sep-08 23:18 
GeneralRe: In My Project Pin
Elkay15-Sep-08 18:04
memberElkay15-Sep-08 18:04 
GeneralRe: In My Project Pin
eusta16-Sep-08 0:09
membereusta16-Sep-08 0:09 
GeneralGood Job Pin
Member 432718817-Jun-08 18:09
memberMember 432718817-Jun-08 18:09 
GeneralLink to original version Pin
James Ashley29-Jun-07 5:10
memberJames Ashley29-Jun-07 5:10 
GeneralRe: Link to original version Pin
Elkay2-Jul-07 8:25
memberElkay2-Jul-07 8:25 
GeneralRe: Link to original version Pin
chimeric693-Jul-07 13:38
memberchimeric693-Jul-07 13:38 
GeneralRe: Link to original version Pin
chimeric693-Jul-07 13:42
memberchimeric693-Jul-07 13:42 
GeneralRe: Link to original version Pin
Elkay10-Jul-07 7:07
memberElkay10-Jul-07 7:07 
GeneralNice Project Pin
StewBob29-Jun-07 4:06
memberStewBob29-Jun-07 4:06 
GeneralVery Good Pin
M Aamir Maniar28-Jun-07 21:46
memberM Aamir Maniar28-Jun-07 21:46 
GeneralExcellent WORK !!! Pin
Marcos Meli28-Jun-07 14:05
memberMarcos Meli28-Jun-07 14:05 
GeneralRe: Excellent WORK !!! Pin
Elkay28-Jun-07 18:13
memberElkay28-Jun-07 18:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 28 Jun 2007
Article Copyright 2007 by Elkay
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid