![](/img/trans.png)
[英]How can I in c# switch input field background color (white/red) on wait?
[英]I need to change background color from white/green flashing to white/red flashing after 10 loops
我有一個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;
}
}
這段代碼有效,但僅適用於上半部分,否則我還沒有找到一種方法。
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;
}
}
使用會話變量(未經測試的代碼,但類似)
...
if (this.BackColor == Color.LightGreen && Session[Click] == 10)
{
int count = Session.[Click];
this.BackColor = Color.White;
Session[Click] = count +1;
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.