none
Countdown Timer of 30 seconds.

    Question

  • Hi all,

     

    I'm currently working on a program. I need codes for a timer to countdown 30 seconds on a button click. When 30 seconds is up, i need it to refresh the page.

    Tuesday, April 24, 2007 7:43 AM

Answers

  • Hi Hockie,

    Try this :

    class TimerForm : Form
        {
            private Timer timer1;
            private System.ComponentModel.IContainer components;
       
            public TimerForm()
            {
                InitializeComponent();
            }

            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.timer1 = new System.Windows.Forms.Timer(this.components);
                this.SuspendLayout();
                //
                // timer1
                //
                this.timer1.Interval = 30000;
                this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
                //
                // TimerForm
                //
                this.ClientSize = new System.Drawing.Size(292, 266);
                this.Name = "TimerForm";
                this.Text = "TimerForm";
                this.Load += new System.EventHandler(this.TimerForm_Load);
                this.ResumeLayout(false);

            }

            private void TimerForm_Load(object sender, EventArgs e)
            {
                timer1.Enabled = true;
                timer1.Start();
            }

            private void timer1_Tick(object sender, EventArgs e)
            {
                RefreshForm();
            }

            private void RefreshForm()
            {
                // This function will be called every 30 seconds.
            }
        }
    Wednesday, April 25, 2007 11:27 AM

All replies

  • Drop a timer on the form. Set its period to 1000ms.
    Attach a handler to the timer.
    Make a note of the time now -> Start Time
    Start the timer.
    Every timer tick, determine elapsed seconds from time now and Start Time.
    Update the button text appropriately.
    When the appropriate time has elapsed, stop the timer and do whatever it is you wanted to do.
    Tuesday, April 24, 2007 8:36 AM
  • Yes i understand what you are trying to say but i'm new to C# so i would require codes along with instructions
    Tuesday, April 24, 2007 8:46 AM
  • Sorry, would take me too long. (I'm at work!)
    Tuesday, April 24, 2007 9:14 AM
  • What type of project you have. By the first post i can assume you have web project, and for that you will need to use some Javascript to develop a delay functionality. You will need setTimeout() javascript method to pause for 30 seconds = 30000 miliseconds. There are many pages on how to use timer methods and here is one of links http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
    Tuesday, April 24, 2007 9:19 AM
  • Hi Hockie,

    Try this :

    class TimerForm : Form
        {
            private Timer timer1;
            private System.ComponentModel.IContainer components;
       
            public TimerForm()
            {
                InitializeComponent();
            }

            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.timer1 = new System.Windows.Forms.Timer(this.components);
                this.SuspendLayout();
                //
                // timer1
                //
                this.timer1.Interval = 30000;
                this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
                //
                // TimerForm
                //
                this.ClientSize = new System.Drawing.Size(292, 266);
                this.Name = "TimerForm";
                this.Text = "TimerForm";
                this.Load += new System.EventHandler(this.TimerForm_Load);
                this.ResumeLayout(false);

            }

            private void TimerForm_Load(object sender, EventArgs e)
            {
                timer1.Enabled = true;
                timer1.Start();
            }

            private void timer1_Tick(object sender, EventArgs e)
            {
                RefreshForm();
            }

            private void RefreshForm()
            {
                // This function will be called every 30 seconds.
            }
        }
    Wednesday, April 25, 2007 11:27 AM