C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: When you invoke ShowDialog, please remember to check the DialogResult. We avoid taking an action when the dialog was canceled.
Here: In this code, we show the ColorDialog instance, and then see if the user clicked the OK button to accept.
IfFinally: If OK was clicked, the parent form's background color is set to the color selected in the dialog.
Example that uses ColorDialog control: C#
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Show the color dialog.
DialogResult result = colorDialog1.ShowDialog();
// See if user pressed ok.
if (result == DialogResult.OK)
{
// Set form background to the selected color.
this.BackColor = colorDialog1.Color;
}
}
}
}
And: If FullOpen is set to True, the full color picker is shown automatically when the ColorDialog is opened.
PropertyBoolNote: It is possible that patterns were once available in the ColorDialog, and these properties could have been used to disable them.
Ints: This is an integer array—you can convert those integers into Color types if necessary.
Color