Click here to Skip to main content
11,928,352 members (48,237 online)
Click here to Skip to main content
Add your own
alternative version


31 bookmarked

Button derived color selection control in C#

, 22 Dec 2003
Rate this:
Please Sign up or sign in to vote.
Button derived color selection control similar to the one used in MS Office applications.

Sample Image - ColorButton.gif


ColorButton is a color selection control derived from System.Windows.Forms.Button similar to the one used in MS Office applications. It uses the same colors like MS Office, including support for "Automatic" and "More Colors".

How To Use

Add a normal Button to your Windows Form and set the Text property to an empty string. Then manually change all occurrences of System.Windows.Forms.Button to ColorButton.ColorButton for this button in the source file.


ColorButton adds the following new properties:

Color (get/set)

Gets or sets the selected color. System.Drawing.Color.Transparent is used for the "Automatic" color.

Automatic (get/set)

Gets or sets the string for the "Automatic" button. Setting this to an empty string disables the "Automatic" color feature.

MoreColors (get/set)

Gets or sets the string for the "More Colors" button. Setting this to an empty string disables the "More Colors" color feature.


ColorButton adds the following new event:


This event occurs whenever the user changes the selected color. Use the Color property to determine what the selected color is.


  • 1.1
    • Added keyboard support to color panel (thanks to Ignazio Di Napoli)
    • Button handles disabled state correctly
    • Button is drawn pushed, if color panel is visible
  • 1.0
    • Initial release


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Thomas Ascher
Web Developer
Austria Austria
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHow to use this in VB Pin
J3ssy Pmntra29-Sep-14 7:13
memberJ3ssy Pmntra29-Sep-14 7:13 
GeneralFixed Control for Clipregion Pin
CodeMonkey3315-Sep-06 7:23
memberCodeMonkey3315-Sep-06 7:23 
Great control! I found a small bug that shows up when another window is dragged over the top of the color control. The button does not draw properly because it is using the clip region as the entire size of the button. I switched the OnPaint call to use 'ClientRectangle' instead and that fixed it for me.

protected override void OnPaint( PaintEventArgs e )
base.OnPaint( e ) ;

int offset = 0 ;

if( panelVisible || ( buttonPushed &&
RectangleToScreen( ClientRectangle ).Contains( Cursor.Position ) ) )
ControlPaint.DrawButton( e.Graphics, e.ClipRectangle, ButtonState.Pushed ) ;
offset = 1 ;

Rectangle rc = new Rectangle( ClientRectangle.Left + 5 + offset,
ClientRectangle.Top + 5 + offset,
ClientRectangle.Width - 24,
ClientRectangle.Height - 11 ) ;


Pen textPen = new Pen( Enabled ? SystemColors.ControlText : SystemColors.GrayText ) ;
Point pt = new Point( rc.Right, ( ClientRectangle.Height + offset ) / 2 ) ;

e.Graphics.DrawLine( textPen, pt.X + 9, pt.Y - 1, pt.X + 13, pt.Y - 1 ) ;
e.Graphics.DrawLine( textPen, pt.X + 10, pt.Y, pt.X + 12, pt.Y ) ;
e.Graphics.DrawLine( textPen, pt.X + 11, pt.Y, pt.X + 11, pt.Y + 1 ) ;

GeneralReworked as a .NET 2.0 ToolStripButton Pin
Greg Ennis7-Mar-06 4:37
memberGreg Ennis7-Mar-06 4:37 
GeneralRe: Reworked as a .NET 2.0 ToolStripButton Pin
shlomifr7-Aug-09 4:05
membershlomifr7-Aug-09 4:05 
GeneralVisual Effects Pin
sleepycoder@hotmail.com29-Aug-04 9:46
membersleepycoder@hotmail.com29-Aug-04 9:46 
GeneralNice Job Pin
Tom Spink22-Dec-03 8:08
memberTom Spink22-Dec-03 8:08 
GeneralRe: Nice Job Pin
Thomas Ascher23-Dec-03 0:22
memberThomas Ascher23-Dec-03 0:22 
GeneralRe: Nice Job Pin
Tom Spink23-Dec-03 1:06
memberTom Spink23-Dec-03 1:06 

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 23 Dec 2003
Article Copyright 2003 by Thomas Ascher
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid