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

代码:

一、新建一个WindowsFormsApplication工程

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

partial class Form1
{ ... ... private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label timerShow;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Timer timer2;
}

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

public partial class Form1 : Form
{ System.Diagnostics.Stopwatch sw;
TimeSpan ts; public Form1()
{
InitializeComponent();
timer2.Interval = ;
sw = new System.Diagnostics.Stopwatch();
ts = sw.Elapsed;
} private void Form1_Load(object sender, EventArgs e)
{ } private void label1_Click(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
sw.Start(); timer2.Start(); ts = sw.Elapsed; timerShow.Text = String.Format("{0:00}天{1:00}小时{2}分{3}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
} private void button2_Click(object sender, EventArgs e)
{
sw.Stop(); ts = sw.Elapsed; timerShow.Text = String.Format("{0:00}天{1:00}小时{2:00}分{3}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
} private void timer2_Tick(object sender, EventArgs e)
{
ts = sw.Elapsed; timerShow.Text = String.Format("{0:00}天{1:00}小时{2:00}分{3:00}秒{4}毫秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); timerShow.Refresh();
} }

效果:

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. Aliyun-CentOS7.3 Init

    Aliyun-CentOS7.3 Init 一.概述 查看系统版本 $ cat /etc/redhat-release $ uname -a 修改主机名 $ vi /etc/hostname $ re ...

  2. 应用程序之Xib自定义Cell

    效果展示 结构分析 代码实现 一.效果展示 二.结构分析 1⃣️首先我们让我们的控制器不再继承UIViewController,而是继承UITableViewController.这样就直接遵守了de ...

  3. Rom Modified [Galaxy 3 Tested]

    1,Virtualbox虚拟机设置-数据空间注意这里不要勾选那个自动挂载,不然后面mount总会提示mount.vbox.. invalid argument. 2,进入ubuntu中,在终端下输入 ...

  4. java使用Runtime.exec()运行windwos dos或linux shell命令

    使用Runtime.exec()运行windwos dos或linux shell命令,按实际情况具体测试     实例代码: package com.bookoo.test.command; imp ...

  5. Oracle 修改带数据的字段类型

    http://www.cnblogs.com/LDaqiang/articles/1157998.html由于需求变动,现要将一个类型NUMBER(8,2)的字段类型改为 char.大体思路如下:   ...

  6. Qt on Android:将Qt调试信息输出到logcat中

    版权全部 foruok .如需转载敬请注明出处(http://blog.csdn.net/foruok). 假设你在目标 Android 设备上执行了 Qt on Android 应用,你可能希望看到 ...

  7. Linux系统rootpassword改动

    重新启动系统. 进入系统引导界面: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzMzOTg1MQ==/font/5a6L5L2T/fontsi ...

  8. Chrome自带恐龙小游戏的源码研究(一)

    目录 Chrome自带恐龙小游戏的源码研究(一)——绘制地面 Chrome自带恐龙小游戏的源码研究(二)——绘制云朵 Chrome自带恐龙小游戏的源码研究(三)——昼夜交替 Chrome自带恐龙小游戏 ...

  9. 设置mysql隔离级别

    1.查看当前会话隔离级别 select @@tx_isolation; 2.查看系统当前隔离级别 select @@global.tx_isolation; 3.设置当前会话隔离级别 set sess ...

  10. Top 10 Open Source Bug Tracking System系统

    Bugzilla http://www.bugzilla.org/ Mantis php http://www.mantisbt.org/ Trac Python also provides wiki ...