' C# Program to Make a Digital Clock using Timer | Infolet

C# Program to Make a Digital Clock using Timer



C# Program to Make a Digital Clock using Timer

This is a simple C# program to create a digital clock. Here timer tool used to update second part in time. To get a timer, open in tool box => All Windows Forms. From given list, search for ‘Timer’. Click and drag timer to your form.

Digital Clock using Timer on C# form

Program name: Clock

Code in ‘form load’ event: timer1.Start();
 -- Where timer1 is the name of timer.

Code in ‘timer tick’ event: (By double click on timer icon, you will get space to write timer tick event): label1.Text = (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString();
--Where label1 is a label in your form.

Over all code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Clock
{
    public partial class Form1 : Form
    {  
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {        
                timer1.Start();
        }
           private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString();
        }
     }
}

Output:

Digital Clock using Timer Make create form on C#



Responses

3 Respones to "C# Program to Make a Digital Clock using Timer"

Chelsea Richards said...
This comment has been removed by a blog administrator.
Anonymous said...

Hi,
This doesn't work;
If you want to make a digiclock use timer.start event in form() initializatin block.


January 4, 2013 at 5:43 PM
Deepak Prajapati said...

you can also use like this!
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("HH:mm:ss");
}


March 4, 2013 at 10:45 AM

Post a Comment

 

Free Updates

Enter your email address:

Delivered by FeedBurner

Learn C

About Author

Author of infolet.org
Muhammed Aslam PK, He is a MCA(Master of Computer Applications) student. See More here
Contact Us
Return to top of page Copyright © 2010 | Infolet.org Google Converted into Blogger Template by HackTutors