When I use this code. I click stop it sets the timer to 00:00. But when I click on start again the timer continues counting from where it stops. Is there a way to reset the timer when I click on stop?
public MainWindow()
{
InitializeComponent();
}
DispatcherTimer timer = new DispatcherTimer();
int increment = 0;
private void Timer()
{
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick += TimerTicker;
TimeSpan time = TimeSpan.FromSeconds(increment);
lblTimer.Content = time.ToString(@"mm\:ss");
}
void TimerTicker(object sender, EventArgs e)
{
increment++;
TimeSpan time = TimeSpan.FromSeconds(increment);
lblTimer.Content = time.ToString(@"mm\:ss");
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
timer.Start();
}
private void btnStop_Click(object sender, RoutedEventArgs e)
{
timer.Stop();
}