如何在c#windows窗体中启动第二个计时器?
我的表单中有两个计时器,我可以在单击按钮时启动第一个计时器,但我也希望在第一个计时器结束时启动第二个计时器。我猜您正在使用倒计时计时器,以便在某处跟踪时间间隔,因此在计时器的eventHandler中可以执行以下操作:如何在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'
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;
}
}
你的第一个计时器什么时候结束?如果您想在第一个计时器运行后启动第二个计时器,请使用第一个计时器的处理程序。我已经启动了。我刚刚开始编程,正在学习。下面是一个很好的示例: