[英]Timer (winforms)
我希望计时器从0到3运行一个计数器。我在Visual Basics 2008中从工具箱添加了计时器(而不是创建对象和使用属性),您可以在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(即1000ms或1秒)。 然后,当您启用它时,它将不断打开,并在每次经过该间隔时触发timer1_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;
}
}
别忘了启用计时器!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.