1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace WindowsFormsApp1 12 { 13 public partial class Form1 : Form 14 { 15 int count; 16 int time; 17 public Form1() 18 { 19 InitializeComponent(); 20 } 21 22 private void label1_Click(object sender, EventArgs e) 23 { 24 25 } 26 27 private void label3_Click(object sender, EventArgs e) 28 { 29 30 } 31 32 private void Form1_Load(object sender, EventArgs e) 33 { 34 int i; 35 for (i = 1; i < 100; i++) 36 { 37 comboBox1.Items.Add(i.ToString()+" 秒"); 38 } 39 label3.Text = ""; 40 comboBox1.Text = "1 秒"; 41 } 42 43 private void timer1_Tick(object sender, EventArgs e) 44 { 45 count++; 46 label1.Text = (time - count).ToString() + "秒"; 47 progressBar1.Value = count; 48 if (count == time) 49 { 50 timer1.Stop(); 51 System.Media.SystemSounds.Asterisk.Play(); 52 MessageBox.Show("时间到了!","提示"); 53 } 54 } 55 56 private void button1_Click(object sender, EventArgs e) 57 { 58 string str = comboBox1.Text; 59 string data = str.Substring(0,2); 60 time = Convert.ToInt16(data); 61 progressBar1.Maximum = time; 62 timer1.Start(); 63 64 } 65 } 66 }
标签:count,c#,Text,void,程序,System,EventArgs,倒计时,using From: https://www.cnblogs.com/powercool/p/17072352.html