Windows Forms: Digital Clock in C#
By FoxLearn 6/25/2017 8:24:36 PM 5.79K
How to make a Digital Clock in C# using Timer Control
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "DigitalClock" and then click OK
Step 2: Design your form as below
You need to add a timer control to your form
Step 3: Add code to handle your form as below
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace DigitalClock { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { lblStatus.Text = DateTime.Now.ToString("T"); } private void Form1_Load(object sender, EventArgs e) { //timer1.Start(); System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 1000; timer.Elapsed += Timer_Elapsed; timer.Start(); } private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //Update label in multiple thread Invoke(new MethodInvoker(delegate () { lblStatus.Text = DateTime.Now.ToString("T"); })); } } }
VIDEO TUTORIALS
Categories
Popular Posts
Responsive Animated Login Form
11/11/2024
Slim Material UI Admin Dashboard Template
11/15/2024
Modular Admin Template
11/14/2024
Freedash bootstrap lite
11/13/2024
SB Admin Template
11/17/2024