C# 计时器(winforms)

C# 计时器(winforms),c#,winforms,timer,C#,Winforms,Timer,我想让计时器运行一个从0到3的计数器。我在VisualBasics2008的工具箱中添加了计时器(而不是创建对象和使用属性),您可以在winform的底部看到计时器 int timerCounter; private void animationTimer_Tick(object sender, EventArgs e) { //timer should go 0,1,2,3..and then reset while (true)

我想让计时器运行一个从0到3的计数器。我在VisualBasics2008的工具箱中添加了计时器(而不是创建对象和使用属性),您可以在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();
        }



    }
计时器能用吗?
(我启用它并将其设置为33毫秒)

将计时器的间隔设置为1000(即1000毫秒或1秒)。然后,当您启用它时,它将持续不断,每次通过间隔时都会触发timer1\u tick事件

下面是一个关于如何做到这一点的示例:

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;
    }
}

别忘了。启用计时器

将计时器的间隔设置为1000(即1000毫秒或1秒)。然后,当您启用它时,它将持续不断,每次通过间隔时都会触发timer1\u tick事件

下面是一个关于如何做到这一点的示例:

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;
    }
}

别忘了。启用计时器

几率约为99%。试着问一个下次能可靠回答的问题。你为什么不自己试试呢?你说的“有用”是什么意思?对你来说什么是重要的?你怎么知道它是否有效?精度重要吗,aso.问题是我有一半的代码在工作。。这是一个大代码的一小部分。。我正在努力避免数小时的调试,几率约为99%。试着问一个下次能可靠回答的问题。你为什么不自己试试呢?你说的“有用”是什么意思?对你来说什么是重要的?你怎么知道它是否有效?精度重要吗,aso.问题是我有一半的代码在工作。。这是一个大代码的一小部分。。我尽量避免几个小时的工作debugging@Dmitry:否,一旦启用计时器,它将继续在窗体上运行,直到您
.enabled=false
它。@Dmitry:否,一旦启用计时器,它将继续在窗体上运行,直到您
.enabled=false
它。