That's because you keep on creating a new checkbox - which does nothing useful for you.
Every time into the method, you create a new checkbox, and give set it's "Checked" property to True. So when you test it to see what you should be doing with teh form size, you always get "Checked" equals True, so you always set the size to 300 by 303.
Instead, delete the
CheckBox CheckBox1 = new CheckBox();
CheckBox1.Checked = true;
lines, and replace
CheckBox1
with the name of the actual CheckBox on your form (probably
checkBox1
, but you may have changed it):
private void ExtandedColorBox(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
this.MaximumSize = new Size(300, 303);
this.Size = new Size(300, 303);
}
else
{
this.MaximumSize = new Size(300, 280);
this.Size = new Size(300, 280);
}
}
In addition, you don't need to check for false explicitly - if it isn't
true
then it is false: I have altered your code to be neater!
BTW: you don't need to keep typing
this.
either - it is implied in all non-static class methods:
private void ExtandedColorBox(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
MaximumSize = new Size(300, 303);
Size = new Size(300, 303);
}
else
{
MaximumSize = new Size(300, 280);
Size = new Size(300, 280);
}
}