Im brand spankin new to C# but did only a bit of console work with C++ in high school.

I am working with the form application walk through and decided to try a few things. I want to have a check box toggle the background of the form between red and blue.

Ive created a checkbox and applied code to make it change the background to red once checked. (The default color is grey)

The problem is, when I uncheck the box it stays red and I can not find any tutorials online to help me with toggling a check box.

Any help would be appritiated greatly.

I don't have a compiler in front of me but this should be close enough to answer your question:

private void checkbox_CheckChanged(sender s, EventArgs e)
{
  if (checkBox1.Checked)
    this.BackgroundColor = Color.Red;
  else
  this.BackgroundColor = Color.Blue;
}

Thank you so much. I didnt know that checkbox had an option for 'Checked' to test if it was checked, thought id have to type the code out.

You're welcome.

Please mark this thread as solved if I have answered your question and good luck!

This question has already been answered. Start a new discussion instead.