Introduction
Every Windows programmer and user knows color chooser controls and dialogs. Surely you see several types of them in several programs. One type of these controls could be a Color Combo Box. I need a color chooser combo box control in one of my projects, to easily select color. Because I couldn't find a suitable one; the best way was to create it myself.
Background
EmrColorComboBox is a NET inherited DLL user control created with C#. It contains Web colors. Users can't add or remove any of the colors. But there is an item titled other to choose colors not listed in the dropped down list. There is a property to set control appearance to standard or skinned.
Control
EmrColorComboBox is an inherited control and its source code; like every NET user control, contains properties, variables and events.
Properties; more than a standard combo box control are:
SelectedColor
ControlColor (The color of the control when the appearance is set to Skinned)
Appearance (Determines if the control displays skinned or standard.)
If you would like to ask more about the source, email me at ampiroid@hotmail.com.
How To Use
To use the control, in the VS.NET environment, right click on tool box and select Add/Remove Items. In Customize Toolbox dialog, select .NET Framework Component and browse EmrColorComboBox. As you select Ok, the control will be added to the toolbox. Simply drag and drop it to your form.
The file you have downloaded contains two folders, one is the compiled EmrColorComboBox with its source code and the other is a demo project.
The demo project is a Windows form with a panel, two checkboxes, a picture box and an EmrColorComboBox.
One of the checkboxes is used to set Combo Box disabled or not and another determines if the control appeared skinned or not.
private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
{
if(this.checkBox2.Checked)
this.colorComboBox1.Appearance =
EmrColorComboBox.ColorComboBox.ControlView.Skinned;
else
this.colorComboBox1.Appearance =
EmrColorComboBox.ColorComboBox.ControlView.Standard;
}
The PictureBox contains a color palette image. As you click picture box, the color of EmrColorComboBox will be changed to the selected color.
As you select a color in EmrColorComboBox panel back color will change to the selected color. If you select "other", standard color dialog box will appear and selecting more colors will be possible.
private void colorComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.panel1.BackColor = this.colorComboBox1.SelectedColor;
}
History
- 30th May, 2006: Initial post