如何在c#windows窗体中启动第二个计时器?

时间:2015-10-15 09:46:22

标签: c# windows-forms-designer

我的表格中有2个计时器,当我点击按钮时我可以启动第一个计时器,但我也想在第一个计时器结束时启动第二个计时器。

1 个答案:

答案 0 :(得分:0)

我猜你正在使用倒数计时器,所以你正在跟踪某个地方的timeLeft,所以在计时器的eventHandler中你可以这样做:

private void Timer_Tick(object sender, EventArgs e)
{
    if(timeLeft > 0)
    {
        //Keep track of the time for timer 1, if it isn't 0 subtract it by 1.
        timeLeft = timeLeft - 1;
    }
    else
    {
        //Means timeLeft reached 0, so we have to stop timer1, and activate timer 2.
        timer1.Stop();
        timer2.Enabled = true;
    }
}