计时器操作只执行了一次

modongming91 2012-04-16 01:03:32
for (j = 3; j > 0; j--)
{

this.timerup.Start();


}


 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次
...全文
204 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
orochiheart 2012-04-16
  • 打赏
  • 举报
回复
设置全局变量int i =0; 函数内每执行一次就i++

在函数内用
if(i>=3)
{
timer.Stop();
}
玲cc 2012-04-16
  • 打赏
  • 举报
回复
设置timer.autoreset = true.
不然你的timer执行一次以后就自动停止了。在你的事件处理函数里面计数,超过3次才调用timer.stop。其余时候不调用。
小志 2012-04-16
  • 打赏
  • 举报
回复
private void timerup_Tick(object sender, EventArgs e)
{




this.ElevatorStyleLeft.Location = new Point(ElevatorStyleLeft.Location.X, ElevatorStyleLeft.Location.Y - 80);

this.timerup.Stop();//执行计时器的Stop()方法后,计时器将停止工作。


}
qlzf11140820 2012-04-16
  • 打赏
  • 举报
回复
int count=0;


if(count>3)
{
this.ElevatorStyleLeft.Location = new Point(ElevatorStyleLeft.Location.X, ElevatorStyleLeft.Location.Y - 80);
}else{
this.timerup.Stop();
}
modongming91 2012-04-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

for循环中直接执行 this.ElevatorStyleLeft.Location 这行代码
[/Quote]
timerup我设置了interval的
bdmh 2012-04-16
  • 打赏
  • 举报
回复
for循环中直接执行 this.ElevatorStyleLeft.Location 这行代码
wangji666666 2012-04-16
  • 打赏
  • 举报
回复
吧this.timerup.Start();
换成timerup_Tick(null,null);
qlzf11140820 2012-04-16
  • 打赏
  • 举报
回复
for (j = 3; j > 0; j--)
{
this.ElevatorStyleLeft.Location = new }


111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧