C#之windows桌面软件第一课:倒时器软件
生活随笔
收集整理的這篇文章主要介紹了
C#之windows桌面软件第一课:倒时器软件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?倒時器軟件
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 WindowsApp_Board_calibrator {public partial class Form1 : Form{int count;//當前秒int time;//設定秒public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){int i;for (i = 1; i < 100; i++)//計數范圍(0-99){comboBox1.Items.Add(i.ToString() + " 秒");//初始化下拉框內容。秒前面有一個空格。}label5.Text = "";comboBox1.Text = "1 秒";//如果不給comboBox1設置初值,當按下開始計時按鈕時程序出錯。1和秒之間有一個空格}private void timer1_Tick(object sender, EventArgs e){count++;//記當前秒label5.Text = (time - count).ToString() + "秒";//顯示剩余時間progressBar1.Value = count;//設置進度條進度if (count == time){timer1.Stop();//如果設定時間和當前時間相等,停止計時System.Media.SystemSounds.Asterisk.Play();//提示音MessageBox.Show("時間到了","提示");//彈出提示框}}private void button1_Click(object sender, EventArgs e){string str = comboBox1.Text;//將下拉框內容添加到一個變量中string data = str.Substring(0, 2);//data得到的是字符time = Convert.ToInt16(data);//把字符轉換成整形的設定定時值//time = Convert.ToInt16(str.Substring(0, 2));progressBar1.Maximum = time;//設置進度條最大數值timer1.Start();//開始計時}} }www.DoYoung.net(部分代碼來至杜洋工作室)
總結
以上是生活随笔為你收集整理的C#之windows桌面软件第一课:倒时器软件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL笔记1:考察内链接、左连接、右
- 下一篇: C#之windows桌面软件第二课:向单