namespace mouseclick {
public partial class Form1 : Form {
private double onetime = 0;
private int downcount = 0;
private bool mousefree = true;
public Form1() {
InitializeComponent();
this.timer1.Interval = 16;
this.timer1.Start();
}
private void Form1_Load(object sender, EventArgs e) {
this.MouseDown += Form1_MouseDown;
this.MouseUp += Form1_MouseUp;
}
void Form1_MouseUp(object sender, MouseEventArgs e) {
mousefree = true;
}
void Form1_MouseDown(object sender, MouseEventArgs e) {
if(e.Button == MouseButtons.Left && mousefree ) {
if (downcount == 0) onetime = DateTime.Now.TimeOfDay.TotalMilliseconds;
downcount++;
mousefree = false;
}
}
void checkmouseclick() {
if (DateTime.Now.TimeOfDay.TotalMilliseconds - onetime > 250 && downcount!=0) {
if (downcount == 1)
this.textBox1.Text = "单击";
else
this.textBox1.Text = "双击";
downcount = 0;
}
}
private void timer1_Tick(object sender, EventArgs e) {
checkmouseclick();
}
}
}