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#


Subscribe To Get Articles On Your Inbox!



4 comments:

  1. Noted on this!!! WOW!! Now this is useful and it surely gets my homework done. Nice!!!
    MagnumClock.com

    ReplyDelete
  2. This just got me the idea for a good countdown method for this New Years Eve!!! Awesome!!!
    MagnumClock.com

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

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

    ReplyDelete

 
Return to top of page Copyright © 2010 | Platinum Theme Converted into Blogger Template by HackTutors GooglePrivacy Policy