0

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.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by sknake
0

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;
}
0

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.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.