Hello,

I have a few checkboxes thatwhen you check them, they set a varible to bool.

For example, if someone selected that they want to see a square it would then change the bool "square = true" however, when someone unchecks the checkbox, I want the boolen to go back to false again, any ideas?

private void squareCheck_CheckedChanged(object sender, EventArgs e)
{
     square = true;
}

Many thanks =)

Recommended Answers

All 5 Replies

Try this:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chBox = sender as CheckBox;
            square = chBox.Checked;
        }

Hey thanks for the reply however it displays an error saying this method already exists. It's rather important too!

Any other suggestions?

Thanks :)

Don't copy the method, put the code from inside the method into the method you posted, replacing it.

I'm confused :(

private void squareCheck_CheckedChanged(object sender, EventArgs e)
{
     CheckBox chBox = sender as CheckBox;            
     square = chBox.Checked;
}

How would I be able to check that it is unchecked?

chBox.Checked is true if it is checked, false if it is not checked. Did you bother to read any documentation on the checkbox?

You'll probably find that 99% of the questions you have can be answered by reading the documentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.