求一个WinForm 计时器

来源:百度知道 编辑:UC知道 时间:2024/05/30 06:23:42
一个label控件显示时间读数,一个按纽可以用回车或空格键控制,按第一次开始记时,再按停止记时,并把第一次的记时数据保存到一个文本文件里,再按读数清零开始记时,以此重复.我会追加重分的!!!!!

偶使用 VS2003 为你编写,已通过调试:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;

private bool isStart = false; // 记录是否启动
private int cnt; // 已经计时的次数
private DateTime beginTime; // 记录启动时的时间
const string FileName = "C:\\time.txt"; // 保存日志的文件名

private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponen