How to pick a color from the color dialog box?

To pick a color from the color dialog box, you need to create an instance of the ColorDialog box and invoke to the ShowDialog() method. The code to display the color dialog box and set the BackColor property of the Label control similar to the color selected in the color dialog box control is:

private void button1_Click(object sender, EventArgs e)
{
 if (colorDialog1.ShowDialog() != DialogResult.Cancel)
 {
 label1.Text = "Here's my new color!";
 label1.BackColor = colorDialog1.Color; 
 }
}


Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*