tft每日頭條

 > 生活

 > 一分鐘計時器的制作方法

一分鐘計時器的制作方法

生活 更新时间:2024-07-18 10:23:08

一分鐘計時器的制作方法(簡單秒表計時器的制作)1

計時器 開始 停止 重置 功能的設計

這個簡單計時器的功能如下:

  • 1、點擊開始,進行計時,此時開始按鈕灰度,停止和重置按鈕正常運行。
  • 2、點擊停止按鈕,計時停止,此時停止按鈕灰度,開始和重置按鈕正常運行。
  • 3點擊重置按鈕,無論當前是計時狀态還是停止狀态,均恢複至開始計時初始界面。

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每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved