blah blah blah is here! blah blah » Close

up0down
link

In Winforms, i've 1 Button.
how to do
1. after button clicked, the back color setup in Red
2. 2nd button clicked, if back color is in red color, the button back color become as normal
how the if else statement looks like?
Me only have this,
if (clickedButton.BackColor = Color.Red)
{
clickedButton.BackColor = System.Drawing.Color.Red;
}
else
{

}
but got an error

last answered 2 years ago

1 answers

up0down
link

A single equals (=) is deemed an assignment whilst a double equals (==) is a comparison.. so in your example the if statement should look somthing like
if (clickedButton.BackColor == Color.Red)
{
clickedButton.BackColor = System.Drawing.Color.Black;
}
else
{
clickedButton.BackColor = System.Drawing.Color.Red;
}
which is saying if the clickedButton back color is red make it black.. else make it red....

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback