Programmatically click on a CheckBox
.net, c#, checkbox, winforms
Solution
Why do you need to simulate a click, doesn't this line of code fits your need?
myCheckBox.Checked = !myCheckBox.Checked;
If you need to execute logic when the state of the CheckBox changes, you should use `CheckedChanged` event instead of `Click`.
private void CheckBox1_CheckedChanged(Object sender, EventArgs e)
{
MessageBox.Show("You are in the CheckBox.CheckedChanged event.");
}
Problem
Is there a way to programmatically generate a click event on a CheckBox? I am looking for an equivalent to Button.PerformClick();