C#做一个秒表

C#做一个秒表
1、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Time0 : MonoBehaviour {

private int hour;
private int minute;
private int second;
private int millisecond;

public  float timeSpend = 0.0f;
public  int MyTime;
public Text text;
private void Update()
{
        timeSpend += Time.deltaTime;
        hour = (int)timeSpend / 3600;
        minute = ((int)timeSpend - hour * 3600) / 60;
        second = (int)timeSpend - hour * 3600 - minute * 60;
        millisecond = (int)((timeSpend - (int)timeSpend) * 1000);
   text.text = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
    
}

2表现效果
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
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(); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

unity学院

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值