User Interface for .NET / User's Guide / Custom Controls / Color Tools

Color Tools
 Overview
Nevron User Interface provides extended and advanced color selection utilities for your applications. Almost every program exposes color selection functionality. Bored from the unseemly and plain default ColorDialog? Nevron Color Picker is just what you need - choose among 3 predefined color types - standard, web and system - or create you own custom color using advanced editing utilities.
 Color Bar

The NColorBar control provides a simple control for visually selecting amount of color through 0-255. Using the left mouse button you can change the value of the control. This control is used in the Nevron Color Picker color customization. Support for horizontal or vertical orientation.

 Luminance Bar

The NLuminanceBar is a predefined color bar used to select a brightness value in the interval 0-255. The only difference is in drawing the color rect of the control.  

 Color Pool

 

 

The NColorPool control provides advanced visual feedback for choosing a color. Moving the cross will change the hue and saturation values of the current color while luminance will remain the same. Although you have access to the hue and saturation values, it is more convenient to use the Color property to alter the current color programmatically.

 

The following example creates new NColorPool and initializes its color value:

C#
Copy Code
NColorPool pool = new NColorPool();
pool.Color = Color.Yellow;
Visual Basic
Copy Code
Dim pool As NColorPool = New NColorPool()
pool.Color = Color.Yellow
 Color Pane

 

This is a predefined NCommandParent control with predefined layout logic. Each cell is a predefined command object. Functionality is exposed by the Color property and ColorChanged event. User controllable cell size and color change logic. By default the ColorChanged event is fired when the mouse is released. The other option is whenever the current selection changes.

 

The following example demonstrates how to create and use NColorPane control:

C#
Copy Code
NColorPane colorPane = new NColorPane();
colorPane.CellSize = new Size(21, 21);
colorPane.ChangeStyle = ColorChangeStyle.OnSelectionChanged;

//specify that the pane can receive focus
colorPane.Selectable = true;
Visual Basic
Copy Code
Dim colorPane As NColorPane = New NColorPane()
colorPane.CellSize = New Size(21, 21)
colorPane.ChangeStyle = ColorChangeStyle.OnSelectionChanged

'specify that the pane can receive focus
colorPane.Selectable = True

 

 

 Color Button

 

The NColorButton provides rich user interface for choosing a color in a drop-down manner. The "More Colors..." command will trigger a NColorDialog for more advanced color selection. Its functionality is exposed by the Color property and ColorChanged event. You can also control size of the color cells via the CellSize property.

 

The following example demonstrates how to create a NColorButton and use its functionality:

C#
Copy Code
NColorButton colorButton = new NColorButton();
colorButton.Color = this.nTextBox1.ForeColor;

//specify a preferred cell size
colorButton.CellSize = new Size(16, 16);
colorButton.ColorChanged += new EventHandler(OnForeColorChanged);

...

private void OnForeColorChanged(object sender, EventArgs e)
{
    NColorButton button = sender as NColorButton;
    this.nTextBox1.ForeColor = button.Color;
}
Visual Basic
Copy Code
Dim colorButton As NColorButton = New NColorButton()
colorButton.Color = Me.nTextBox1.ForeColor

'specify a preferred cell size
colorButton.CellSize = New Size(16, 16)
AddHandler ColorChanged, AddressOf OnForeColorChanged

...

Private Sub OnForeColorChanged(ByVal sender As Object, ByVal e As EventArgs) Handles colorButton.ColorChanged 
    Dim button As NColorButton = TryCast(sender, NColorButton)
    Me.nTextBox1.ForeColor = button.Color
End Sub
 Color Listbox

 

Nevron User Interface provides you with a predefined listbox used to display color values. You have access to the selected color via the Color property. You can add other items to the list also. The control provides three methods for populating types of colors - Know Colors, SystemColors and Web Colors. You can also add custom colors.

 

The following example demonstrates how to create and use color listbox:

C#
Copy Code
NColorListBox colorList = new NColorListBox();
//populate system colors
colorList.PopulateSystemColors();
colorList.SelectedIndexChanged += new EventHandler(OnColorListSelectedIndexChanged);

...

private void OnColorListSelectedIndexChanged(object sender, EventArgs e)
{
    NColorListBox list = sender as NColorListBox;
    MessageBox.Show(list.Color);
}
Visual Basic
Copy Code
Dim colorList As NColorListBox = New NColorListBox()
'populate system colors
colorList.PopulateSystemColors()
AddHandler SelectedIndexChanged, AddressOf OnColorListSelectedIndexChanged

...

Private Sub OnColorListSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles colorList.SelectedIndexChanged
    Dim list As NColorListBox = TryCast(sender, NColorListBox)
    MessageBox.Show(list.Color)
End Sub
 Color Combobox

 

 

The NColorComboBox provides the same functionality as the NColorListBox. Actually the drop-down part of the combo is NColorListBox. Being entirely custom, the Nevron ComboBox enables you to reuse common listboxes.

 Color Picker And Color Dialog

 

Putting all the tools together results in the advanced NColorDialog - use it in the same way as the standard ColorDialog. You may however use the NColorPicker control stand-alone and create your custom Color Dialog.