Home > Net >  C # how to realize the point a label control switch a color
C # how to realize the point a label control switch a color

Time:11-05

Want a label to the background color, in accordance with the order of the Bai Honglan each click a switch, code, and didn't think

CodePudding user response:

Novice ah, that we will not introduce you to what MVVM, data binding, a state machine class of senior stuff, global variables are not out, even in the click event once get the

 private void button1_Click (object sender, EventArgs e) 
{
The object tag=for. The tag;
int i=0;
If (tag!=null)
{
I=(int) tag;
I=(I + 1) % 3.

}

The switch (I)
{
Case 0:
For the BackColor=Color. White;
break;
Case 1:
For the BackColor=Color. Red;
break;
Case 2:
For the BackColor=Color. Blue;
break;
Default:
break;
}

For the. Tag=I;

}
  •  Tags:  
  • C#
  • Related