最近开始学习C#,用倒计时项目练练手
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { int time, count=0; public Form1() { InitializeComponent(); int i; for (i = 0; i < 100; i++) { comboBox1.Items.Add(i.ToString() + " s"); } comboBox1.Text = "1 s"; label2.Text = "0 s"; } private void button1_Click(object sender, EventArgs e) { string str = comboBox1.Text;//将下拉框的内容提取出来 label2.Text = str; time = Convert.ToInt16(str.Substring(0,2)); count = 0; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { count++; label2.Text = (time - count).ToString()+ "s"; if (time == count) { timer1.Stop(); MessageBox.Show("时间到了"); } } } }