简体   繁体   中英

Timer (winforms)

i want timer to run a counter from 0 to 3. i added the timer from the toolbox in visual basics 2008 (instead of creating an object and using properties) you can see the Timer at the bottom of the winform..

        int timerCounter;
    private void animationTimer_Tick(object sender, EventArgs e)
    {
        //timer should go 0,1,2,3..and then reset
        while (true)
        {
            timerCounter++;
            if (timerCounter > 3)
            {
                timerCounter = 0;
            }
            game.Twinkle();
            //screen gets repainted.
            Refresh();
        }



    }

will the timer work? (i enabled it and set it to 33 milliseconds)

Set the timer's interval to 1000 (which is 1000ms or 1 second). Then when you enable it, it'll go on and on and on, firing the timer1_tick event every time it goes through the interval.

Here's an example on how to do it:

int count = 0;
private void timer1_Tick(object sender, EventArgs e)
{
    count++;

    if (count == 3)
    {
        //Do something here, because it's the third toll of the bell.

        //But also reset the counter after you're done.
        count = 0;
    }
}

Don't forget to .Enable the timer!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM