首先,设定Timer控件的Enabled属性为True,Interval属性为1000(单位为毫秒)。
然后,添加程序代码如下:
private void timer1_Tick(object sender, EventArgs e)
{
if (this.label1.BackColor == Color.Red) //判断当前背景色是否为红色
this.label1.BackColor = Color.Blue; //如果是则变为蓝色
else //如果当前背景色不是红色
this.label1.BackColor = Color.Red; //将背景色变为红色
}
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.BackColor =this.label1.BackColor == Color.Red?Color.Blue:Color.Red;
}
时间设为1000.
this.label1.BackColor = this.label1.BackColor == Color.Red?Color.Blue:Color.Red;
private void timer1_Tick(object sender, EventArgs e)
{
if (this.label1.BackColor == Color.Red)
this.label1.BackColor = Color.Blue;
else
this.label1.BackColor = Color.Red;
}