示意图:六个lable,三个文本框,一个but即可 timer控件或自定义一个
以下是代码实现的部分
public int ConvertInt32(string name) { if (name != "" && name != null) { return Convert.ToInt32(name); } else { return 0; } } int Hose, Minut, Second = 0; //public void ComdTimer() //{ // if (button1.Text == "设置")//判断按钮的文本是否为设置 // { // button1.Text = "停止";//设置按钮的文本为停止 // timer2.Start();//启动timer2计时器 // } // else if (button1.Text == "停止")//判断按钮的文本是否为停止 // { // button1.Text = "设置";//设置按钮的文本为设置 // timer2.Stop();//停止timer2计时器 // label3.Text = "倒计时已取消"; // } //} private void button1_Click(object sender, EventArgs e) { Hose = ConvertInt32(textBox1.Text.Trim()); if (ConvertInt32(textBox2.Text.Trim()) > 60) { MessageBox.Show("不能大于60分钟"); return; } else { Minut = ConvertInt32(textBox2.Text.Trim()); } if (ConvertInt32(textBox3.Text.Trim()) >= 60) { MessageBox.Show("不能大于60秒"); return; } else { Second = ConvertInt32(textBox3.Text.Trim()); } this.timer1.Start(); this.timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { if (Second != 0) { Second--; //给Viz发东西 } if (Second == 0) { if (Minut != 0) { Second += 60; Minut--; } } if (Minut == 0) { if (Hose != 0) { Minut += 60; Hose--; } } label3.Text = Hose.ToString(); label2.Text = Minut.ToString(); label1.Text = Second.ToString(); }