2

I have five button and a menu strip, I want to apply the color on button based on the menustip click.

Suppose I have btn1, btn2, btn3, and menu stip which items are Test1, Test2, and Test3. When I click on Test1 then btn1 color should become orange, when I click Test2 and btn1 color become white and btn2 color become orange, same as Test3.

some one please help me.

4

1 回答 1

2

Define the events of your Menu strip Items and you can do the following to change the color of buttons...

private void Test1ItemClick(object sender, EventArgs e)
{
    btn1.BackColor = Color.Orange;
}

private void Test2ItemClick(object sender, EventArgs e)
{
    btn1.BackColor = Color.White;
    btn2.BackColor = Color.Orange;
}

Remember There is no css for buttons in win forms.

Updated:

void ChangeColor(string menuItem)
{
  switch(menuItem)
  {
    case "Test1":
      btn1.BackColor = Color.Orange;
      break;
    case "Test2":
      btn1.BackColor = Color.White;
      btn2.BackColor = Color.Orange;
      break;
     // and so on
  }
}
于 2012-07-09T05:15:17.557 回答