C#或VB.NET中,如何用timer控件给Label.BackColor来回变色闪动?

2024-11-23 00:13:51
推荐回答(4个)
回答1:

首先,设定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; //将背景色变为红色
}

回答2:

private void timer1_Tick(object sender, EventArgs e)
{
this.label1.BackColor =this.label1.BackColor == Color.Red?Color.Blue:Color.Red;
}
时间设为1000.

回答3:

this.label1.BackColor = this.label1.BackColor == Color.Red?Color.Blue:Color.Red;

回答4:

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;
}