Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing Winform Button Colors

I have got four buttons in my form among four three buttons (btn2 btn3 btn4) have same color.

when btn1 is clicked it will check if btn2 btn3 and btn4 are of same color without explicitly stating what color to compare. but my condition does not seem to be right should i state this

the code I'm using is:

private void btn1_Click(object sender, EventArgs e)
{
    if (btn2.BackColor.Equals((btn3.BackColor) && (btn4.BackColor)))
       {
         MessageBox.Show("ALL BUTTONS ARE OF SAME COLOR");
       } 
}
like image 816
Tacit Avatar asked Dec 01 '25 18:12

Tacit


1 Answers

Use this code to compare colors:

        if (btn2.BackColor == btn3.BackColor && btn3.BackColor == btn4.BackColor)
        {
            MessageBox.Show("ALL BUTTONS ARE THE SAME COLOR");
        }
        else
        {
            MessageBox.Show("ALL BUTTONS ARE NOT THE SAME COLOR");
        }
like image 97
Gregor Primar Avatar answered Dec 03 '25 09:12

Gregor Primar