計時器 開始 停止 重置 功能的設計
這個簡單計時器的功能如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Exercise { public partial class 計時器 : Form { private DateTime timeSum; public 計時器() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.timeSum = new DateTime(0); //開始顯示時間 0.0.0:0 this.label1.Text = timeSum.Hour "." timeSum.Minute "." timeSum.Second ":" timeSum.Millisecond; this.button2.Enabled = false; } private void IncreaseTime(double seconds) { this.timeSum = this.timeSum.AddSeconds(seconds); this.label1.Text = timeSum.Hour "." timeSum.Minute "." timeSum.Second ":" timeSum.Millisecond; } private void timer1_Tick(object sender, EventArgs e) { this.IncreaseTime(0.1); } private void button1_Click(object sender, EventArgs e) { this.timer1.Start(); this.button1.Enabled = false; this.button2.Enabled = true; } private void button2_Click(object sender, EventArgs e) { this.timer1.Stop(); this.button1.Enabled = true; this.button2.Enabled = false; } private void button3_Click(object sender, EventArgs e) { this.timeSum = new DateTime(0); //開始顯示時間 0.0.0:0 this.timer1.Stop(); this.label1.Text = timeSum.Hour "." timeSum.Minute "." timeSum.Second ":" timeSum.Millisecond; this.button1.Enabled = true; this.button2.Enabled = true; } } }
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!