Press "Enter" to skip to content

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 ‘seconds‘ 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.

C# Program to Make a Digital Clock using Timer

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:

Output for C# Program to Make a Digital Clock using Timer

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *