Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Yet Another Color Picker for C#, VB.NET WinForm

5.00/5 (5 votes)
17 Aug 2013CPOL 35.5K   3  
An Office 2010 Style Color Picker for .NET WinForm.

Introduction

An alternative of color picker control for C#, VB.NET WinForm's color dialog. 

There is currently only 1 style in this project. If you have some other color picker that would like to share, you may join this project at yetcolorpicker.codeplex.com.

About the control 

http://yetcolorpicker.codeplex.com

Another rebuild Office 2010 Style color picker.

Image 1 

Three components are built based on Office 2010 Style color picker:

  • ThemeColorPicker - Used in WinForm
  • ThemeColorPickerWindow - A small pop-up tool box
  • ThemeColorPickerToolStripButton - A ToolStripButton used in Tool Strip Control

Using the control 

Add a reference of ThemeColorPicker into your project. 

ThemeColorPicker

Image 2 
  1. If you add the source code directly into project, ThemeColorPicker should appear at the ToolBox.
  2. However, if you can't the it at ToolBox, you can try drag n drop the DLL into the ToolBox.
  3. Then, drag and drop it from ToolBox into WinForm.
  4. If you can't drag and drop from ToolBox, you can manually add it in the Form's Designer.cs file.
  5. Double click on the control to create/handle the event of ColorSelected

C#
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void themeColorPicker1_ColorSelected(object sender, ColorSelectedArg e)
    {
        this.BackColor = e.Color;
    }
} 

ThemeColorWindow

This component is created dynamically in codes. 

C#
private void button1_Click(object sender, EventArgs e)
{
    Point pt = this.PointToScreen(button1.Location);
    ThemeColorPickerWindow f = new ThemeColorPickerWindow(
        pt,
        System.Windows.Forms.FormBorderStyle.FixedToolWindow,
        ThemeColorPickerWindow.Action.CloseWindow,
        ThemeColorPickerWindow.Action.CloseWindow);
    f.ColorSelected += new ThemeColorPickerWindow.colorSelected(f_ColorSelected);
}

void f_ColorSelected(object sender, ColorSelectedArg e)
{
    this.BackColor = e.Color;
} 

ThemeColorPickerToolStripButton  

You can see a new option of adding a ThemeColorPickerToolStripButton at the tool strip:

Image 3

Handle the ColorSelected event at code behind:

C#
public Form1()
{ 
    InitializeComponent();
    themeColorPickerToolStripButton1.ColorSelected += new ThemeColorPickerToolStripButton.colorSelected(themeColorPickerToolStripButton1_ColorSelected);
}

void themeColorPickerToolStripButton1_ColorSelected(object sender, ColorSelectedArg e)
{
    this.BackColor = e.Color;
}  

License

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