0

代码是:

private void timer1_Tick(object sender, EventArgs e)
        {
            count += 1;
            countBack --;
            TimerCount.Text = TimeSpan.FromSeconds(countBack).ToString();
            TimerCount.Visible = true;
            if (count == 300)
            {
                timer1.Enabled = false;
                count = 0;
            }
        }

我在变量计数之前使用了计数到 5 分钟。但我只想使用 countBack 变量从 5 分钟倒数到 0,并将其显示在 TimerCount 中。

countBack 是 int 并且在构造函数中我只是将其设置为 5。 countBack = 5;

我怎样才能使我只使用 countBack 并且当它到达 0 时停止计时器将 countBack 重置为 5 并在 TimerCount 中显示 countBack ?

4

1 回答 1

2
    private void timer1_Tick(object sender, EventArgs e)
    {
        count ++;
        countBack = 5 - count/60;
        TimerCount.Text = TimeSpan.FromSeconds(count).ToString();
        if(!TimerCount.Visible) TimerCount.Visible = true;
        if (count == 300){
            timer1.Enabled = false;
            count = 0;
        }
    }

注意:上面的代码只是对您的代码的简单修改,我们可以在更具体的上下文中做得更好。

于 2013-09-29T07:07:49.270 回答