user3177361
user3177361

Reputation: 67

How do I create a color picker?

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?

Upvotes: 4

Views: 4997

Answers (1)

Nate Jenson
Nate Jenson

Reputation: 2794

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;

Upvotes: 5

Related Questions