日期:2014-05-19  浏览次数:20903 次

c# 设置定时器
想在一个WINFORM上设置一个倒计时1分钟的定时器,请教,我是个新手~

------解决方案--------------------
//基本功能完成,再细的话,你自己改一下吧

System.Timers.Timer t = new System.Timers.Timer();
System.Windows.Forms.Timer timer1 = new Timer();
private bool bCom = false;
private void button1_Click(object sender, EventArgs e)
{
//System.Timers.Timer t = new System.Timers.Timer(1 * 1 * 60 * 1000);
t.Interval = 60 * 1000; //1分钟
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
t.Enabled = true;


timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
bCom = false;

}

void timer1_Tick(object sender, EventArgs e)
{
if (bCom)
{
timer1.Enabled = false;
}

this.label1.Text = DateTime.Now.ToLongTimeString();
}


private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
{
// MessageBox.Show( "hello ");
if ( bCom )
{
t.Enabled = false;
}
bCom = true;
}