Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#windows窗体中启动第二个计时器?_C#_Windows Forms Designer - Fatal编程技术网

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

如何在c#windows窗体中启动第二个计时器?,c#,windows-forms-designer,C#,Windows Forms Designer,我的表单中有两个计时器,我可以在单击按钮时启动第一个计时器,但我也希望在第一个计时器结束时启动第二个计时器。我猜您正在使用倒计时计时器,以便在某处跟踪时间间隔,因此在计时器的eventHandler中可以执行以下操作: private void Timer_Tick(object sender, EventArgs e) { if(timeLeft > 0) { //Keep track of the time for timer 1, if it isn'

我的表单中有两个计时器,我可以在单击按钮时启动第一个计时器,但我也希望在第一个计时器结束时启动第二个计时器。

我猜您正在使用倒计时计时器,以便在某处跟踪时间间隔,因此在计时器的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;
    }
}

你的第一个计时器什么时候结束?如果您想在第一个计时器运行后启动第二个计时器,请使用第一个计时器的处理程序。我已经启动了。我刚刚开始编程,正在学习。下面是一个很好的示例: