using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
textBox1 = "";
button2.Enabled = false;
button3.Enabled = false;
} int h = 0;
int m = 0;
int s = 0;
int ms = 0;//毫秒 private void button3_Click(object sender, EventArgs e)//结束按钮
{
timer1.Enabled = false;
button1.Enabled = true;
button2.Enabled = false;
button3.Enabled = false; textBox1.Text = "";
listBox1.Items.Clear();
} private void button1_Click_1(object sender, EventArgs e)//开始按钮
{
textBox1 = "0:0.0 0";
listBox1.Items.Clear();
timer1.Enabled = true;
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
} private void button2_Click_1(object sender, EventArgs e)//记录按钮
{
listBox1.Items.Add(textBox1.text);
} private void timer1_Tick_1(object sender, EventArgs e)//时钟控件,频率为 1 毫秒
{
if (ms < 999)
ms++;
else
{
ms = 0;
if (s < 59)
s++;
else
{
s = 0;
if (m < 59)
m++;
else
{
m = 0;
h++;
}
}
} textBox1.Text = "" + h + ":" + m + "." + s + " " + ms + "";//小时: 分. 秒 毫秒
} }
}不知为何,显示结果极不准确……
解决方案 »
- 读取日志工具,计算时间方法第二次没有进方法体,直接默认值了,请高手帮忙解决,不甚感激!!!
- comboBox获取文本档每行的数据
- GDI+bitmap 自己 封装的图片打印不清楚。。。
- 如何将利用C#将DataGridView中的数据道出到EXcel或者是World??
- 发个自定义圆形Button(希望对新手有用)
- C#得到最後一個id 的值
- 如何学好MS SQL SERVER的存储过程?
- mutex 不起作用的问题 求救!!!
- button事件丢失(请高手指教)
- 这次真的要高手出手帮忙了,我编的系统本来没问题的,但是莫名其妙的就除了这个错误,希望高手指点( 我没分可给了)
- 大数据的查询和比对
- 关于SQL查询结果中增加空行,求高手帮忙啊
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
DateTime dtbegin = DateTime.MinValue; public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "0:0.0 0";
listBox1.Items.Clear();
timer1.Enabled = true;
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true; if (this.dtbegin == DateTime.MinValue)
{
this.dtbegin = DateTime.Now;
}
} private void button2_Click(object sender, EventArgs e)
{
dtbegin = DateTime.MinValue; timer1.Enabled = false;
button1.Enabled = true;
button2.Enabled = false;
button3.Enabled = false; textBox1.Text = "";
listBox1.Items.Clear();
} private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
} private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Text="";
button2.Enabled = false;
button3.Enabled = false;
} private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan tstemp = DateTime.Now - this.dtbegin;
this.textBox1.Text = tstemp.Hours.ToString()+":" + tstemp.Minutes.ToString()+":" + tstemp.Seconds.ToString()+":" + tstemp.Milliseconds.ToString();
}
}
}
http://download.csdn.net/detail/zlcoolzl/4260786
if (this.dtbegin == DateTime.MinValue)
为什么要加这句?