[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Display custom colors in the color selection dialog in C#

custom colors

The color selection dialog can display custom colors in the 16 boxes on its lower left (see the picture). Your code can initialize those colors by setting the dialog's CustomColors property to an array of integers representing the colors.

One easy way to define the colors is using hexadecimal format. The first two digits represent a color's blue component, the next two its green component, and the last two its red component.

The following code shows how this example initializes the custom colors for the background color selection dialog shown in the picture.

// Use light custom colors for the background dialog. int[] bg_colors = { 0xFFFFFF, 0xFFC0C0, 0xFFE0C0, 0xFFFFC0, 0xC0FFC0, 0xC0FFFF, 0xC0C0FF, 0xFFC0FF, 0xE0E0E0, 0xFF8080, 0xFFC080, 0xFFFF80, 0x80FF80, 0x80FFFF, 0x8080FF, 0xFF80FF }; dlgBgColor.CustomColors = bg_colors;

If you set the dialog's FullOpen property to true, the dialog shows its custom color selection area on the right when it opens. This example uses the following code to make the background color dialog start with this area open and the foreground color dialog start with this area closed.

dlgBgColor.FullOpen = true; dlgFgColor.FullOpen = false;

That's all there is to it. Now just display the dialogs normally by calling their ShowDialog methods.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.