Jump to content

Timer - Count Down


Dkid
 Share

Recommended Posts

Boas pessoal, estou com um problema a trabalhar com o timer...

O que pretendo é que haja um tempo especifico (240 segundos) e que esses 240 segundos sejam vistos a decrescer numa label, até zero

Mas estou com problemas a faze-lo alguem me pode ajudar ?

Obrigado

I promise that I will not change the PATH variable again other than:PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Link to comment
Share on other sites

Tens várias formas de fazer isso.

Se queres usar um timer, então aconselhava-te a teres um período pequeno, tipo 1 segundo. Em cada tick então decrescerias o valor na label. Quando chegasse a zero, fazias stop ao timer.

"Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !"

Sign on a computer system consultant's desk

Link to comment
Share on other sites

Aqui vai o codigo  🙂

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Count_Down
{
    public partial class Form1 : Form
    {
        private Int32 iCountDown = 240;
        public Form1()
        {
            InitializeComponent();
            label1.Text = iCountDown.ToString();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            iCountDown -= 1;
            label1.Text = iCountDown.ToString();
            if (iCountDown == 0)
            {
                timer1.Stop();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Interval = 1000;
            iCountDown = 240;
            timer1.Start();
        }
    }
}
Link to comment
Share on other sites

Boas, obrigado pelas respostas

O que pretendia era tao simples que se tivesse olhado melhor, mesmo sem nunca ter usado o Timer tinha realizado...

        int tempo = 10;
        private void timer1_Tick(object sender, EventArgs e)
        {
              tempo--;
              label1.Text = tempo.ToString();
        }

I promise that I will not change the PATH variable again other than:PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.