Reputation: 8815
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
textBox1.Enabled = checkBox1.Checked;
}
private void Form1_Load(object sender, EventArgs e)
{
checkBox1.Checked = false;
}
I set the check state in load event handler, and why in this case, the CheckedChanged not fired? If i click the check box, then the CheckedChanged is fired.
Upvotes: 4
Views: 6225
Reputation: 216273
If your checked state is initially false
, then setting it to false
again doesn't fire the CheckedChanged
event.
That happens because the checked state isn't actually changed
This is the internal code used when trying to set the CheckBox1.Checked
property
public void set_Checked(bool value)
{
if (value != this.Checked)
{
this.CheckState = value ? CheckState.Checked : CheckState.Unchecked;
}
}
Upvotes: 7