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:
Subscribe To Get Articles On Your Inbox!
Labels:
C#
Previous Article


Noted on this!!! WOW!! Now this is useful and it surely gets my homework done. Nice!!!
ReplyDeleteMagnumClock.com
This just got me the idea for a good countdown method for this New Years Eve!!! Awesome!!!
ReplyDeleteMagnumClock.com
Hi,
ReplyDeleteThis doesn't work;
If you want to make a digiclock use timer.start event in form() initializatin block.
you can also use like this!
ReplyDeleteprivate void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("HH:mm:ss");
}