Sunday, February 16, 2014

Timer Example

    public partial class Form1 : Form
    {
        Timer timer1 = new Timer();
        int counter = 0;

        public Form1()
        {
            InitializeComponent();
            timer1.Interval = 1000;
            timer1.Tick += new EventHandler(timer1_Tick);
        }

        private void timer1_Tick(object Sender, EventArgs e)
        {
            lblCounter.Text = counter.ToString();
            counter++;
        }

        private void btnTimer_Click(object sender, EventArgs e)
        {
            if (btnTimer.Text.Equals("Start"))
            {
                btnTimer.Text = "Stop";
                timer1.Enabled = true;

            }
            else
            {
                btnTimer.Text = "Start";
                timer1.Enabled = false;
            }
        }
    }

1 comment: