[英]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.