我还有另一个计时器来倒计时timerCounter
只是为了视觉帮助。
我想要的是再次单击开始按钮以运行程序 单击“停止/重置”按钮后,但操作失败。
下面是我的代码部分,我怀疑如何在start button
click事件中重新启动程序。
private void btnStart_Click(object sender, EventArgs e)
{
// file system watcher, timer and one other function inside this event handler
_timeLeft = (int)numUpDown.Value;
timerCounter.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
_timer.Stop();
timerCounter.Stop();
_timer.Dispose();
numUpDown.Value = 0;
timeLabel.Text = 0 + @" seconds";
lblResult.Text = @"Program has stopped, press start button to
process again.";
_fsw.Dispose();
}
private void timerCounter_Tick(object sender, EventArgs e)
{
if (_timeLeft > 0)
{
_timeLeft = _timeLeft - 1;
timeLabel.Text = _timeLeft + " seconds";
lblResult.Text = $@"Process began and counting down {timeLabel.Text} in seconds";
}
else
{
timerCounter.Stop();
timerCounter.Enabled = false;
timeLabel.Text = $@"Time's up";
}
}