简单秒表计时器的制作

秒表计时器
标题

 

这个简单计时器的功能如下:

  • 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;

        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值