Help On Timer Control

Posted by Vijayar under C# on 8/4/2011 | Points: 10 | Views : 1611 | Status : [Member] | Replies : 1
Hi
i need a timer, Actually i need Counting Up that should be like this 00:00:01, 00:00:02........... 00:and stops when i click on save button,the time can be displayed in a label.It's very urgent,Help me with an attachment either in c# or javascript

vijaya


Responses

Posted by: Hmanjarawala on: 8/4/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi Vijaya,

Sry i couldn't attach code here, but do as i per my instructions.

Put Timer Control on Form and Set Interval Property to 1000 miliseconds.
Define hour, minute and second as private integer variable of Form1 as below:

int hh=0,m==0,ss=0;

Put Lable control on Form:

Set Text property of Label control in Form_Load event

private void Form1_Load(Object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString("hh:mi:ss tt");
}

then write code for Timer1_Tick event:
private void Timer1_Tick(Object sender, EventArgs e )
{
ss++;
if(ss==60)
{
ss=0;
mm++;
}
if(mm==60)
{
ss=0;
mm=0;
hh++;
}
Label1.Text = string.Format("{0}:{1}:{2}", hh,mm,ss);
}

put a button to stop timer and write code on it's click event

private button1_Click(Object sender, EventArgs e )
{
Timer1.Stop()
}

Hope this code will helps you

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response