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?
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.
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.
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.
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.
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With