我有一个Visual Studio表单,我需要将10次循环后的白色/绿色闪烁的背景颜色更改为白色/红色闪烁。
private void Timer1_Tick(object sender, EventArgs e)
{
if (this.BackColor == Color.LightGreen)
{
this.BackColor = Color.White;
}
else
{
this.BackColor = Color.LightGreen;
}
}
此代码有效,但仅适用于上半部分,否则我还没有找到一种方法。
答案 0 :(得分:-1)
public int count = 0;
private void Timer1_Tick(object sender, EventArgs e)
{
this.count++;
if(this.count == 10)
{
if (this.BackColor == Color.Red)
{
this.BackColor = Color.White;
}
else
{
this.BackColor = Color.Red;
}
}
else {
if (this.BackColor == Color.LightGreen)
{
this.BackColor = Color.White;
}
else
{
this.BackColor = Color.LightGreen;
}
this.count = 0;
}
}
答案 1 :(得分:-2)
使用会话变量(未经测试的代码...但是类似的东西)
...
if (this.BackColor == Color.LightGreen && Session[Click] == 10)
{
int count = Session.[Click];
this.BackColor = Color.White;
Session[Click] = count +1;
}
...