Jeff B
Jeff B

Reputation: 8982

Looking for an event that fires only when user checks a CheckBox

System.Windows.Forms.ComboBox has two different events that the programmer can handle:

Is there something similar for System.Windows.Forms.CheckBox?

Clarification: I'm looking for an event to handle that won't be fired when I programmatically set the checkbox by calling a statement like CheckBox.Checked = true.

Upvotes: 5

Views: 1605

Answers (3)

Rehan Ahmad Khan
Rehan Ahmad Khan

Reputation: 116

As Control.focused is true only when the user has clicked on the control with the mouse, you can use the following code to respond only when the user checks the checkbox

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Focused)
    {
        //do ur stuff here
    }
}

Upvotes: 4

Igby Largeman
Igby Largeman

Reputation: 16747

Just handle the Click event. Any time a checkbox is clicked, it will be toggled.

    private void checkBox1_Click(object sender, EventArgs e)
    {
        if (((CheckBox)sender).Checked)
        {
            // do stuff
        }
    }

Upvotes: 5

Fredou
Fredou

Reputation: 20100

you want this event? (CheckBox.CheckedChanged)

Upvotes: 1

Related Questions