I am trying to make a buttons forecolor change when clicked and when it is clicked again it will revert back to its original color and it loops that. Basically like a toggle that changes the color of a button when clicked and when clicked again reverts it to its original color. I am doing this in c# and I have searched Multiple forums for an answer to this and no one has this specific problem so I am asking if you can please help me with the code. I have no code now because I do not know what to start with and ive tried multiple different things that havent worked.
I have tried to have the buttons forecolor change when clicked which is easy but then reverting it back is hard and then looping it is something i cant seem to get working right now. None of my code works so I just request if it is possible a kind forum member can assist me with my code or provide me with code i need. Thank You.
CodePudding user response:
Well, it's not that hard. Just write something like that in action you want:
if (button1.ForeColor != Color.Green)
{
button1.ForeColor = Color.Green;
}
else
{
button1.ForeColor = Color.Red;
}