a timer object can be used to acheive this simple task

all yo have to do is 
1)drag an drop a timer from the tool box
2)go to properties of the timer
3)set the intervel to the number of miliseconds you want to raise the tick event
4)select the Tick event and double click it
an event handler will get creteated automatically

add the following code inside it's body

private void timer1_Tick(object sender, EventArgs e)
        {
            int hours = DateTime.Now.Hour;
            int minutes = DateTime.Now.Minute;
            int seconds = DateTime.Now.Second;
            int milSeconds = DateTime.Now.Millisecond;

            string timeString =hours+" : "+minutes + " : " + seconds + " : " + milSeconds;

            label1.Text = timeString;
        }

what happens here is every time the tick event of timer 1 occur the label.text value will get updated with the curent time of the system
you can get those values using the DateTime struct in the System namesapce
 now press F5 and "volla" there goes your own digital clock
you can extend this simple code to tailor your needs very easyly
.NET Z DAT SIMPLE DUDE :-)

0 comments:

Post a Comment