倒数计时器问题 [英] countdown timer problem

查看:105
本文介绍了倒数计时器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙伴

我制作倒数计时器,经过10秒 int count * 2 再次重置倒数计时器。

i make countdown timers , after 10 secounds int count * 2 and again reset countdown timers.

我想要每10秒计算5次* 2并且及时5停止计时器。

i want 5 time per 10 sec count * 2 and in time 5 stop timer.

  private DateTime startTime;
        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = TimeSpan.FromSeconds(10).ToString("dd\\:hh\\:mm\\:ss");
            timer1.Interval = 1000;
        }

        public void counter()
        {
            int count = 300;
            count = count * 2;
            label2.Text = count + " $";
            label1.Text = (TimeSpan.FromSeconds(10) - (DateTime.Now - startTime)).ToString("dd\\:hh\\:mm\\:ss");
            startTime = DateTime.Now;
            timer1.Start();

        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(timer1.Interval <= 0)
            {
                counter();
            }
            else
            {
                label1.Text = (TimeSpan.FromSeconds(10) - (DateTime.Now - startTime)).ToString("dd\\:hh\\:mm\\:ss");
            }
         
       
        }

        private void button1_Click(object sender, EventArgs e)
        {
            startTime = DateTime.Now;
            timer1.Start();
        }

推荐答案

您的描述有点令人困惑。 你是说你要10秒,然后"计数"双打,然后10秒,然后计数双打,然后10秒,然后计数双打,并在第5次之后,停止计数?

Your description is a little confusing.  Are you saying you want 10 seconds, then "count" doubles, then 10 seconds, then count doubles, then 10 seconds, then count doubles, and after the 5th time, stop the counting?

第一个问题是"计数"必须是类成员变量。 你现在拥有它的方式,"计数"每次计数器触发时都会重置为300。 第二个问题是计时器间隔永远不会小于0. 
如果你想每秒更新一次,但每10秒钟采取一次其他行动,那么你必须做"10到0"。自己倒计时。

The first problem is that "count" must be a class member variable.  The way you have it now, "count" will reset to 300 every time counter fires.  The second problem is that the timer Interval is never going to be less than 0.  If you want to update the time every second but take other action every 10 seconds, then you have to do the "10 to 0" countdown yourself.

    private int countdown;
    private int countdown;
    private DateTime startTime;

    private void Form1_Load(object sender, EventArgs e)
    {
        label1.Text = TimeSpan.FromSeconds(10).ToString("dd\\:hh\\:mm\\:ss");
        timer1.Interval = 1000;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        countdown = 50;
        counter = 300;
        startTime = DateTime.Now;
        timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if( (--countdown % 10) == 0 )
        {
            count *= 2;
            label2.Text = count + "


" ;;
}

label1.Text = TimeSpan.FromSeconds(倒计时%10))。ToString(" 00:ss");

if(countdown == 0)
{
timer1.Stop();
}
}

"; } label1.Text = TimeSpan.FromSeconds(countdown%10)).ToString("00:ss"); if( countdown == 0 ) { timer1.Stop(); } }


这篇关于倒数计时器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆