参考:http://zhidao.baidu.com/link?url=j-jxQJenrO54BSKJ_IkXWbhdDqbVLUyyenjjSGs8G0xdisgBZ0EMhzyWgARSFct6rTP5BaabDacbTOvoxhijg_

代码:

一、新建一个WindowsFormsApplication工程

在Design设计区中,从ToolBox拖了四个控件:两个Buttion、一个Label、一个Timer,下面是Form1.cs中自动生成的对应的初始化代码

  1. partial class Form1
  2. {
  3.  
  4. ... ...
  5.  
  6. private System.Windows.Forms.Button button1;
  7. private System.Windows.Forms.Label timerShow;
  8. private System.Windows.Forms.Button button2;
  9. private System.Windows.Forms.Timer timer2;
  10. }

二、设计区上双击控件进入对应的方法,所有控件对应的方法代码如下:

  1. public partial class Form1 : Form
  2. {
  3.  
  4. System.Diagnostics.Stopwatch sw;
  5. TimeSpan ts;
  6.  
  7. public Form1()
  8. {
  9. InitializeComponent();
  10. timer2.Interval = ;
  11. sw = new System.Diagnostics.Stopwatch();
  12. ts = sw.Elapsed;
  13. }
  14.  
  15. private void Form1_Load(object sender, EventArgs e)
  16. {
  17.  
  18. }
  19.  
  20. private void label1_Click(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24.  
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27. sw.Start();
  28.  
  29. timer2.Start();
  30.  
  31. ts = sw.Elapsed;
  32.  
  33. timerShow.Text = String.Format("{0:00}天{1:00}小时{2}分{3}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
  34. }
  35.  
  36. private void button2_Click(object sender, EventArgs e)
  37. {
  38. sw.Stop();
  39.  
  40. ts = sw.Elapsed;
  41.  
  42. timerShow.Text = String.Format("{0:00}天{1:00}小时{2:00}分{3}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
  43. }
  44.  
  45. private void timer2_Tick(object sender, EventArgs e)
  46. {
  47. ts = sw.Elapsed;
  48.  
  49. timerShow.Text = String.Format("{0:00}天{1:00}小时{2:00}分{3:00}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
  50.  
  51. timerShow.Refresh();
  52. }
  53.  
  54. }

效果:

C# 计时器 以“天时分秒毫秒”形式动态增加显示的更多相关文章

  1. JS时间处理,获取天时分秒

    //获取时间的天,小时,分钟,秒 function ToTime(second) { second = second / ; var result ; ) % ; ) % ; * )); ) { re ...

  2. JS时间处理,获取天时分秒。以及浏览器出现的不兼容问题

    //获取时间的天,小时,分钟,秒 function ToTime(second) { second = second / ; var result ; ) % ; ) % ; * )); ) { re ...

  3. JQ倒计时天时分秒

    <div id="times_wrap" class="time_num"> 距离现在时间: <div class="time_w& ...

  4. JS倒计时——天时分秒

      HTML代码: <div id="times_wrap" class="time_num">    距离结束时间:     <div cl ...

  5. SqlSever基础 getdate函数 返回系统当前的年月日,时分秒 毫秒

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  6. 年月日时分秒毫秒+随机数getSerialNum

    package com.creditharmony.apporveadapter.core.utils; import java.io.ByteArrayInputStream; import jav ...

  7. Asp.net(C#)年月日时分秒毫秒

    年月日时分秒毫秒格式:yyyyMMddHHmmssfff

  8. Python:求时间差(天时分秒格式)

    传入一个时间戳,以天时分秒格式打印出时间差 输入一个10位的时间戳,求出时间差 def time_diff(timestamp): onlineTime = datetime.datetime.fro ...

  9. C语言获取字符年月日时分秒毫秒

    概述 本文演示环境: Windows10 使用C语言获取年月日时分秒毫秒, 代码 #include <iostream> #include <string> #include ...

随机推荐

  1. 线段树专题—ZOJ1610 Count the Colors

    题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...

  2. 2016.6.21 -Dmaven.multiModuleProjectDirectory system propery is not set,Check $M2_HOME environment variable and mvn script match.

    eclipse中使用maven插件的时候,运行run as maven build的时候报错: -Dmaven.multiModuleProjectDirectory system propery i ...

  3. log4j.properties(信息打印)

    ### set log levels ###log4j.rootLogger = INFO , console , debug , error ### console ###log4j.appende ...

  4. Direct-X学习笔记--纹理映射

    一.介绍 之前学习了如何绘制物体,还画了个DX自带的茶壶,然而这个东东并不怎么好看....离我们现实的物体简直相隔千里. 仅仅能说像美术他们用来写生的模型...那么要怎么样才干让我们的东西看起来更像真 ...

  5. MySQL常用经典语句

    http://www.cnblogs.com/see7di/archive/2010/04/27/2239909.html MySQL常用经典语句 .重命名表ALTER TABLE tbl1 RENA ...

  6. Anaconda2

    Anaconda 是一个打包的python,一次把好多需要的包都安装好了.对于Python2.7把PyQt5都弄好了,不需要自己来编译! 看看这个 http://conda.pydata.org/do ...

  7. centos 6.9 x86 安装搭建hadoop集群环境

    又来折腾hadoop了 文件准备: centos 6.9 x86 minimal版本 163的源 下软件的时候可能会用到 jdk-8u144-linux-i586.tar.gz ftp工具 putty ...

  8. 使用Erlang和Thrift,与Hbase通信(转)

    操作系统是Ubuntu Server 12.10 先安装Thrift sudo apt-get install libboost-dev libboost-test-dev \ libboost-pr ...

  9. Ubuntu64位安装Adobe Reader 9.5.5

    Aodbe Reader在Linux下的效果比Foxit Reader(福昕阅读器)要好一些,尤其对于中文文档而言.本文介绍Adobe Reader在Ubuntu下的安装,文章<Ubuntu12 ...

  10. IT痴汉的工作现状10-Sprint Planning

    这是我们的第四个Sprint了.因为上一个迭代周期的失利,Leader群发邮件这样描写叙述道:"对任务的乐观预计,导致Sprint 3没有如期完毕. 我们须要在这次Sprint计划中细致评估 ...