C# windows窗体应用小程序 秒表 可实现记录 计时 清零 停止功能

在这里,我要向大家介绍一个简易的C#窗体应用的简易秒表,其中这个可以实现计时,停止,添加,清楚的功能。
其实这个很简单,下面这张图片是开发过程中所用到的一些控件。
其中还用到了定时器timer 定时器的使用就是设置他的时间间隔interval 以及如何启动定时器比如timer. start() 或者是timer.enabled=true。
这里又添加了一个新的函数,带走返回值的out_put () ,我定义了一个全局变量count然后对count实现自加,最后将count 传给out_put 函数,然后对其变形,最后返回字符串,然后让textbox 输出。

在这里插入图片描这是这个简易秒表 用到控件   述

namespace windows__窗体__test2测试
{
   
    public partial class Form1 : Form
    {
   
        public int count = 0;   //定义一个全局变量
        int h, mm, ss, ms;   //定义  小时  分钟  毫秒  
        public Form1()
        {
   
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
   
            textBox1.Text = DateTime.Now.
  • 6
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
namespace StopWatch { public partial class Form2 : Form { DateTime examtime; DateTime nowtime; DateTime t = DateTime.Now; int add = 0; public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { timer1.Enabled = false; examtime = new DateTime(1, 1, 1, 0,0, 0); labTime.Text = "0" + examtime.ToLongTimeString(); if (t.Hour < 10) labT.Text = "0" + DateTime.Now.ToLongTimeString(); else labT.Text = DateTime.Now.ToLongTimeString(); } private void button2_Click(object sender, EventArgs e) { if (add < 1 ) { starttime(); } else { MessageBox.Show("记录已满,请清除记录后再开始记录!"); } } private void button1_Click(object sender, EventArgs e) { if (timer1.Enabled != false) { Add(); } if (add >= 5) { MessageBox.Show("对不起!最多只能记录4条!!"); timer1.Enabled = false; } } private void button3_Click(object sender, EventArgs e) { ClearTime(); add = 0 - 1; Add(); stoptime(); } private void button4_Click(object sender, EventArgs e) { Application.Exit(); } private void timer1_Tick(object sender, EventArgs e) { examtime = examtime.AddSeconds(1); if (examtime.Hour < 10) labTime.Text = "0" + examtime.ToLongTimeString(); else labTime.Text = examtime.ToLongTimeString(); } private void timer2_Tick(object sender, EventArgs e) { if(t.Hour<10) labT.Text = "0"+DateTime.Now.ToLongTimeString(); else labT.Text = DateTime.Now.ToLongTimeString();nowtime = nowtime.AddSeconds(1); } private void Add() { add = add + 1; switch (add) { case 1: textBox1.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = true; break; case 2: textBox2.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = true; break; case 3: textBox3.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = true; break; case 4: textBox4.Text = "0" + examtime.ToLongTimeString(); Program.hash.add(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text); timer1.Enabled = true; timer1.Enabled = false; break; case 5: default: break; } } private void ClearTime() { examtime = new DateTime(1, 1, 1, 0, 0, 0); labTime.Text = "0" + examtime.ToLongTimeString(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox1.Text = "0" + examtime.ToLongTimeString(); textBox2.Text = "0" + examtime.ToLongTimeString(); textBox3.Text = "0" + examtime.ToLongTimeString(); textBox4.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = false; } private void starttime() { timer1.Enabled = true; } private void stoptime() { timer1.Enabled = false; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void textBox4_TextChanged(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } private void textBox5_TextChanged(object sender, EventArgs e) { } private void labTime_Click(object sender, EventArgs e) { } private void timeshow_Click(object sender, EventArgs e) { Form3 frm = new Form3(); frm.Show(); } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值