namespace CountDown

    public partial class Form1 : Form
    {
        public int counter = 0;

        public Form1()
        {
            InitializeComponent();
        }

         private void btnStart_Click(object sender, EventArgs e)
        {
            int parsedValue;

            if (!int.TryParse(txtInput.Text, out parsedValue))
            {
                MessageBox.Show("Please Enter Numbers Only");
            }
            else
            {
                counter = Convert.ToInt32(txtInput.Text);

                timer1 = new Timer();
                timer1.Tick += new EventHandler(timer2_Tick);
                timer1.Interval = 1000 * 60; // 1 second converts to 1 minute by adding * 60

                timer1.Start();
                lblDisplay.Text = counter.ToString();

                lblDisplay.Text = txtInput.Text;
                lblDisplay.Visible = true;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            counter--;
            if (counter == 0)

            timer1.Stop();
            lblDisplay.Text = counter.ToString();
        }
    }

Recommended Answers

All 3 Replies

Was there a question here?

Forgot to post a follow up question but thats the code am using to do a count down timer in MINUTES. I need to also display minutes and seconds at the same time. MIN:SEC. Please help

Wait, do you need some formula to show text from an integer of seconds to minutes? That seems something rather basic.

That is, are you asking folk to code this for you?

PS. I'm sure you are seeing more and more folk ask for code. In this discussion you appear to be asking for code you expect a first year coder to be able to handle.

Q. What's eluding you here? Is it the math or somethign else?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.