65.9K
CodeProject is changing. Read more.
Home

Button derived color selection control in C#

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.21/5 (14 votes)

Dec 18, 2003

1 min read

viewsIcon

83303

downloadIcon

1163

Button derived color selection control similar to the one used in MS Office applications.

Sample Image - ColorButton.gif

Introduction

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.

Properties

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.

Events

ColorButton adds the following new event:

Changed

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

History

  • 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