Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a color picker?

Tags:

c#

This is the code I have so far:

private void btnColour_Click(object sender, EventArgs e)
    {
        //show the colour dialog and check that user clicked ok
        if (clrDialog.ShowDialog() == DialogResult.OK)
        {
            //save the colour that the user chose
            c = clrDialog.Color;
        }
    }

Color c = Color.Black;

Isn't it supposed to be working? maybe I have selected the wrong event?

like image 556
user3177361 Avatar asked Nov 02 '25 01:11

user3177361


1 Answers

You should create the Dialog in the event handler instead of outside, try something like this:

private void btnColour_Click(object sender, EventArgs e)
{
    ColorDialog clrDialog = new ColorDialog();

    //show the colour dialog and check that user clicked ok
    if (clrDialog.ShowDialog() == DialogResult.OK)
    {
        //save the colour that the user chose
        c = clrDialog.Color;
    }
}

Color c = Color.Black;
like image 113
Nate Jenson Avatar answered Nov 03 '25 15:11

Nate Jenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!