Hello everyone welcome to my programming channel. I will show you how to make countdown timer.
Let’s develop a simple count down using C sharp and windows form.
You may also like :C# Create Countdown with Timer
Click new project, open a new form and drop labels, text box, button and timer control to form from toolbox.
Set controls names as;
- label1 -> lbCounter
- textbox1 ->txtSeconds
- button1 -> btnStart
- timer1 -> timer1
Attach btsStart and timer1 to the program by double click and change program codes as below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public partial class Form1 : Form { int seconds; public Form1() { InitializeComponent(); } private void btnStart_Click(object sender, EventArgs e) { seconds = Convert.ToInt32(txtSeconds.Text); txtSeconds.Enabled = false; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { lbCounter.Text = seconds--.ToString(); if(seconds < 0) { timer1.Stop(); txtSeconds.Enabled = true; } } } |
Result: