Here I’m going to create timer at runtime.

I’ll set timer’s interval to 5seconds=5000miliseconds. And after 5sec back color of form will be changed to blue.

  //creating timer
  Timer tm = new Timer();
//at button click event setting timer interval to 5000 and enabling the timer
        private void btnClick_Click(object sender, EventArgs e)
            tm.Interval = 5000;
            tm.Enabled = true;
//writing timer event handler at tick event of timer.
        private void tm_Tick(object sender, EventArgs e)
            this.BackColor = Color.Blue;
            tm.Enabled = false;
//at form load event creating timer event handler
        private void Timer2_Load(object sender, EventArgs e)
            tm.Tick += new EventHandler(tm_Tick);

 Screen shot

Back color of form changed after 5 seconds of button click

  Modified On Nov-30-2017 04:33:11 AM

Leave Comment