c# 倒计时怎么写?

波波007 2011-08-02 04:58:16
        
int mint = 10;
int scss = 59;
private void time_s_Load(object sender, EventArgs e)
{

label1.Text = string.Empty;
this.timer1.Interval =1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.timer1.Start();

}

private void timer1_Tick(object sender, EventArgs e)
{
if (mint >=0)
{

scss--;
if (scss == 0)
{
mint--;
label1.Text = mint.ToString();
scss = 59;
} label2.Text = scss.ToString();
}

}


这样的倒计时怎么是间隔2秒!
...全文
825 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
小松618 2013-05-23
  • 打赏
  • 举报
回复
这个做出来了之后 我想在窗体上添加一个按钮 设置 可以自己随意设置未来的时间 然后进行倒计时 这个该怎么做呢
chxg99 2011-08-03
  • 打赏
  • 举报
回复
mark
小D2013 2011-08-02
  • 打赏
  • 举报
回复
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

楼主我99.9999999999%肯定在designer.cs文件中还有这样一句话
catchdream 2011-08-02
  • 打赏
  • 举报
回复
你新建页面,只拖3个控件:2个label,一个timer,然后把代码拷上去,就是1秒;如果你设置了在form页面设置了timer的click事件为timer1_Tick,这样相当于timer1_Tick调用了2次,就是2秒了。另外,你的代码分钟没显示出来,可以修改timer1_Tick如下:
private void timer1_Tick(object sender, EventArgs e)
{
if (mint >= 0 && scss > 0)
{
scss--;
if (scss == 0)
{
mint--;
scss = 59;
}
label1.Text = mint.ToString();
label2.Text = scss.ToString();
}
}
mamxfx 2011-08-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yes16ws 的回复:]

C# code

int seed = 1000;//设置间隔秒数
//以下使用System.Timers.Timer类
System.Timers.Timer myTimer = new System.Timers.Timer(seed); //实例化Timer类
……
[/Quote]

+1
guojh021 2011-08-02
  • 打赏
  • 举报
回复
你不要调试,直接运行,看看结果。

用你的代码,我这里看的是一秒变一下。
catchdream 2011-08-02
  • 打赏
  • 举报
回复
你这个就是一个倒计时啊,还是说你需要其他形式的?说明白
solicice 2011-08-02
  • 打赏
  • 举报
回复
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);去掉就行了!
全局变量 2011-08-02
  • 打赏
  • 举报
回复

int seed = 1000;//设置间隔秒数
//以下使用System.Timers.Timer类
System.Timers.Timer myTimer = new System.Timers.Timer(seed); //实例化Timer类
myTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件;
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Function); //到达时间的时候执行事件myTimer_Function;
myTimer.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
/// <summary>
/// 被定时器调用的方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void myTimer_Function(object sender, System.Timers.ElapsedEventArgs e)
{
//你要操作的代码
}
波波007 2011-08-02
  • 打赏
  • 举报
回复
各位大侠给个方案或者给个代码!谢谢了!!各位大哥

110,571

社区成员

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

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

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