ColorDialog colorDlg = new ColorDialog(); if (colorDlg.ShowDialog() == DialogResult.OK) { // Use the selected color Color selectedColor = colorDlg.Color; // Do something with the selected color }
ColorDialog colorDlg = new ColorDialog(); colorDlg.AllowFullOpen = true; // Allow custom colors colorDlg.Color = Color.Red; // Set initial color if (colorDlg.ShowDialog() == DialogResult.OK) { // Use the selected color Color selectedColor = colorDlg.Color; // Do something with the selected color }This example shows how to customize the ColorDialog to allow the user to select custom colors and set an initial color value. The code waits for the user to click OK, then retrieves the selected color and uses it for further processing. The ColorDialog class is part of the .NET Framework, specifically the System.Windows.Forms namespace.