计时器操作只执行了一次,该如何处理
计时器操作只执行了一次C# codefor (j 3 j 0 j--){this.timerup.Start()}C# code private void tim
计时器操作只执行了一次
C# codefor (j = 3; j > 0; j--) { this.timerup.Start(); }
C# code private void timerup_Tick(object sender, EventArgs e) { this.ElevatorStyleLeft.Location = new Point(ElevatorStyleLeft.Location.X, ElevatorStyleLeft.Location.Y - 80); this.timerup.Stop(); }
为什么timer只执行了一次,怎样才能执行3次
[解决办法]int count=0;
if(count>3)
{
this.ElevatorStyleLeft.Location = new Point(ElevatorStyleLeft.Location.X, ElevatorStyleLeft.Location.Y - 80);
}else{
this.timerup.Stop();
}
[解决办法]private void timerup_Tick(object sender, EventArgs e)
{
this.ElevatorStyleLeft.Location = new Point(ElevatorStyleLeft.Location.X, ElevatorStyleLeft.Location.Y - 80);
this.timerup.Stop();//执行计时器的Stop()方法后,计时器将停止工作。
}
[解决办法]设置timer.autoreset = true.
不然你的timer执行一次以后就自动停止了。在你的事件处理函数里面计数,超过3次才调用timer.stop。其余时候不调用。
[解决办法]设置全局变量int i =0; 函数内每执行一次就i++
在函数内用
if(i>=3)
{
timer.Stop();
}