Timer Control demo in C#

Download
Download is available until [expire_date]
  • Version
  • Download 51
  • File Size 43.89 KB
  • File Count 1
  • Create Date April 25, 2016
  • Last Updated April 25, 2016

Timer Control demo in C#

Timer Control demo in C#

Sample program that demonstrates how to use timer control in c#. This sample program will allow the user to start and stop the timer. The value of the label starts at 0 and once you clicked the start button the value of the label will increment by 1.

Source 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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
            num = 0;
            label2.Text = "Timer Started";
        }
        int num = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            num++;
            label1.Text = num.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (button2.Text == "Stop")
            {
                timer1.Stop();
                button2.Text = "Resume";
                label2.Text = "Timer Stopped";
            }
            else if (button2.Text == "Resume")
            {
                timer1.Start();
                button2.Text = "Stop";
                label2.Text = "Timer Resumed";
            }
            
        }
    }
}
, , , , ,

Post navigation

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.