日期:2014-05-18 浏览次数:20843 次
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 + "";//小时: 分. 秒 毫秒 } } }