How to: Display a Color Palette
You can use the built-in ColorDialog component to display a color dialog box instead of creating your own color palette. For example, you can enable users to select a color to apply to a Windows form when they click a button on the form.
To display the color dialog box
On the File menu, click New Project.
The New Project dialog box appears.
Click Windows Forms Application and then click OK.
From the Toolbox, drag a Button control to the form, and change the following properties in the Properties window:
Property
Value
Name
formColor
Text
Color
Drag a ColorDialog component from the Dialogs tab of the Toolbox to the form.
colorDialog1 appears in the component tray.
Double-click the Color button to create the default event handler in the Code Editor.
In the formColor_Click event handler, add the following code to display the color dialog box and change the background color of the form according to the user's choice.
if (colorDialog1.ShowDialog() == DialogResult.OK) { this.BackColor = colorDialog1.Color; }
Press F5 to run the code.
When the form opens, click Color, click a color in the resulting dialog box, and then click OK.
Verify that the chosen color is applied to the form.
Close the application.
See Also
Concepts
Using Built-in Dialog Boxes in Your Application
Designing a User Interface in Visual C#