using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace WindowsFormsApplication32 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } DateTime dt; bool end = false; private void Form1_MouseDown(object sender, MouseEventArgs e) { if (end) MessageBox.Show((DateTime.Now - dt).ToString()); else dt = DateTime.Now; end = !end; } } }
private DateTime LastClickTime=DateTime.Now;每次点击的时候DateTime t=DateTime.Now;
TimeSpan=(TimeSpan)t.SubStract(LastClickTime);
textbox1.Text=TimeSpan.TotalSecond.ToString();
LastClickTime=t;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication32
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} DateTime dt;
bool end = false; private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (end)
MessageBox.Show((DateTime.Now - dt).ToString());
else
dt = DateTime.Now;
end = !end;
}
}
}
当第二次点击时给个判断,如果记数器是已经是1了,则记录下当前时间,将当前时间与那个存放的时间进行比较,并输出来,同时将记数器归零,
这样的话,就可记录下两次点击的时间差,很简单的
这是我的想法,你可试一试,由于现在要出去一趟,没时间给你写代码,自己写吧,多动手锻炼一下,不难