Search for an event that fires only when the user checks the CheckBox

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

  • SelectionChangeCommitted - the event fires only when the user changes the selected item
  • SelectedIndexChanged - an event also occurs when a selection changes programmatically

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

Explanation: I am looking for an event to handle that will not be fired when I programmatically select a checkbox by calling an expression of type CheckBox.Checked = true .

+4
source share
3 answers

Just handle the Click event. Each time a flag is clicked, it will be toggled.

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

Since Control.focused is true only when the user 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 } } 
+1
source

Source: https://habr.com/ru/post/1379673/


All Articles