Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms' CheckBox CheckedChanged vs. CheckStateChanged

Windows Forms' CheckBox control implements both CheckedChanged and CheckStateChanged events. As far as I can tell, both fire when the checked status of the checkbox is changed.

CheckedChanged precedes CheckStateChanged, but other than that I see no difference. Am I missing something? Should one be preferred over another?

like image 918
BojanG Avatar asked May 06 '10 16:05

BojanG


People also ask

What is the difference between CheckedChanged and CheckStateChanged?

The CheckedChanged event is fired before the CheckStateChanged event, so if you bind to Checked , your binding is in between the two events, but if you bind to CheckState , your binding is after them.

Which CheckBox is automatically checked when you open an event window?

When the AutoCheck property is true (the default), the CheckBox is automatically selected or cleared when it is clicked. Otherwise, you must manually set the Checked property when the Click event occurs. You can also use the CheckBox control to determine a course of action.

What is CheckBox windows form?

CheckBox allows the user to make multiple selections from a provided options. It is used to give a user an option, such as true/false or yes/no. You can click a CheckBox to select it and click it again to deselect it. The CheckBox is a useful control in Windows Forms platform and the C# language.


2 Answers

CheckState (and thus CheckStateChanged) allow for using a checkbox that can have three values: it can be checked, unchecked or 'indeterminate' - i.e. it has ThreeState set to true.

If you're not using ThreeState, then CheckedChanged is all you need.

like image 186
stuartd Avatar answered Sep 25 '22 23:09

stuartd


My guess would be that it has to do with tri-state checkboxes. This is the guts of the CheckState setter:

 if (this.checkState != value)  {    bool flag = this.Checked;    this.checkState = value;    if (base.IsHandleCreated)    {      base.SendMessage(0xf1, (int) this.checkState, 0);    }    if (flag != this.Checked)    {      this.OnCheckedChanged(EventArgs.Empty);    }    this.OnCheckStateChanged(EventArgs.Empty);  } 
like image 42
Jacob G Avatar answered Sep 22 '22 23:09

Jacob G