adam gills

adam gills

  • NA
  • 65
  • 14.4k

Set timer on Start botton click

Jan 28 2017 12:01 AM
Hi,
I build a timer which is start on click button and stop after 10 minutes.
I want to know that if click on start button during timer running then its restart from  0,
but timer not reset .
 
 int minremain =600000;
private void timer1_Tick(object sender, EventArgs e)
{
minremain = minremain - 60;
string Sec = string.Empty;
string Min = string.Empty;
if (minremain <= 0)
{
lbltimer.Text = "";
timer1.Stop();
return;
}

else
{

var timeSpan =TimeSpan.FromMilliseconds(Convert.ToDouble(minremain));
var seconds = timeSpan.Seconds;
var minutes = timeSpan.Minutes;
if (seconds.ToString().Length.Equals(1))
{
Sec = "0" + seconds.ToString();
}
else
{
Sec = seconds.ToString();
}
if (minutes.ToString().Length.Equals(1))
{
Min = "0" + minutes.ToString();
}
else
{
Min = minutes.ToString();
}
string Totaltime = "Remaing Time: " + Min + ":" + Sec;
lbltimer.Text = Totaltime;


 
 
private void btnstartrefresh_Click(object sender, EventArgs e)
{

timer1.Start();
}
 
So please tell me how to reset timer from start position.

Answers (3)