C# 计时器 以“天时分秒毫秒”形式动态增加显示
参考: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# 计时器 以“天时分秒毫秒”形式动态增加显示的更多相关文章
- JS时间处理,获取天时分秒
//获取时间的天,小时,分钟,秒 function ToTime(second) { second = second / ; var result ; ) % ; ) % ; * )); ) { re ...
- JS时间处理,获取天时分秒。以及浏览器出现的不兼容问题
//获取时间的天,小时,分钟,秒 function ToTime(second) { second = second / ; var result ; ) % ; ) % ; * )); ) { re ...
- JQ倒计时天时分秒
<div id="times_wrap" class="time_num"> 距离现在时间: <div class="time_w& ...
- JS倒计时——天时分秒
HTML代码: <div id="times_wrap" class="time_num"> 距离结束时间: <div cl ...
- SqlSever基础 getdate函数 返回系统当前的年月日,时分秒 毫秒
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- 年月日时分秒毫秒+随机数getSerialNum
package com.creditharmony.apporveadapter.core.utils; import java.io.ByteArrayInputStream; import jav ...
- Asp.net(C#)年月日时分秒毫秒
年月日时分秒毫秒格式:yyyyMMddHHmmssfff
- Python:求时间差(天时分秒格式)
传入一个时间戳,以天时分秒格式打印出时间差 输入一个10位的时间戳,求出时间差 def time_diff(timestamp): onlineTime = datetime.datetime.fro ...
- C语言获取字符年月日时分秒毫秒
概述 本文演示环境: Windows10 使用C语言获取年月日时分秒毫秒, 代码 #include <iostream> #include <string> #include ...
随机推荐
- 线段树专题—ZOJ1610 Count the Colors
题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...
- 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 ...
- log4j.properties(信息打印)
### set log levels ###log4j.rootLogger = INFO , console , debug , error ### console ###log4j.appende ...
- Direct-X学习笔记--纹理映射
一.介绍 之前学习了如何绘制物体,还画了个DX自带的茶壶,然而这个东东并不怎么好看....离我们现实的物体简直相隔千里. 仅仅能说像美术他们用来写生的模型...那么要怎么样才干让我们的东西看起来更像真 ...
- MySQL常用经典语句
http://www.cnblogs.com/see7di/archive/2010/04/27/2239909.html MySQL常用经典语句 .重命名表ALTER TABLE tbl1 RENA ...
- Anaconda2
Anaconda 是一个打包的python,一次把好多需要的包都安装好了.对于Python2.7把PyQt5都弄好了,不需要自己来编译! 看看这个 http://conda.pydata.org/do ...
- centos 6.9 x86 安装搭建hadoop集群环境
又来折腾hadoop了 文件准备: centos 6.9 x86 minimal版本 163的源 下软件的时候可能会用到 jdk-8u144-linux-i586.tar.gz ftp工具 putty ...
- 使用Erlang和Thrift,与Hbase通信(转)
操作系统是Ubuntu Server 12.10 先安装Thrift sudo apt-get install libboost-dev libboost-test-dev \ libboost-pr ...
- Ubuntu64位安装Adobe Reader 9.5.5
Aodbe Reader在Linux下的效果比Foxit Reader(福昕阅读器)要好一些,尤其对于中文文档而言.本文介绍Adobe Reader在Ubuntu下的安装,文章<Ubuntu12 ...
- IT痴汉的工作现状10-Sprint Planning
这是我们的第四个Sprint了.因为上一个迭代周期的失利,Leader群发邮件这样描写叙述道:"对任务的乐观预计,导致Sprint 3没有如期完毕. 我们须要在这次Sprint计划中细致评估 ...