Reputation: 8982
System.Windows.Forms.ComboBox
has two different events that the programmer can handle:
SelectionChangeCommitted
- event fires only when the user changes the selected itemSelectedIndexChanged
- event is also raised when the selection changes programmaticallyIs 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
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
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