关于倒计时的问题

caterpillar12345 2010-10-13 11:10:55
有一个timer
如何才能让timer.Stop()的时候再执行timer.Start()之后的代码呢?
...全文
116 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
caterpillar12345 2010-10-13
  • 打赏
  • 举报
回复

while (stationNum1 < stationSum1)
{
Random rd = new Random();

time1 = rd.Next(5, 10);

timer1.Enabled = true;

this.timer1.Interval = 1000;

timer1.Start();

bt1_Click(bt1, e);
}

private void timer1_Tick(object sender, EventArgs e)
{
if (time1 > 0)
{
time1--;
label_time_1.Text = time1.ToString();
}
else
{
timer1.Stop();
}
}



这段代码的话,如何才能让timer1.Stop()执行之后再执行Click呢???
bloodish 2010-10-13
  • 打赏
  • 举报
回复
最后一句就是你想要的



void timer_Tick(object sender, EventArgs e)
{
//todo
}
Timer t = new Timer();
t.Interval = 100;
t.Tick += new EventHandler(timer_Tick);
t.Start();
t.Stop();
timer_Tick(t, EventArgs.Empty);
Ny-6000 2010-10-13
  • 打赏
  • 举报
回复
委托.

调用.
gouhan02 2010-10-13
  • 打赏
  • 举报
回复
那你就不要stop或者再timer.Start()就可以了
wuyq11 2010-10-13
  • 打赏
  • 举报
回复
private int inter= 30;
private void timer1_Tick(object sender, EventArgs e)
{
if(inter>=0)
{
this.label1.Text = inter.ToString();
inter--;
}
}
Timer.Stop();
System.Threading.Thread.Sleep(10000)
Timer.Start();

111,129

社区成员

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

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

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