C # counting clicks

A simple application using a timer has been made that counts the number of clicks on the panel for a given duration ... simple enough, everything works, except that it does not seem to be counted fast enough to register all mouse clicks?

I literally increase the value of private int in the panel click event and show a message box with the results by tick. Any ideas? Code below ...

Mt.

public partial class Form1 : Form { int click = 0; public Form1() { InitializeComponent(); } private void panel1_Click(object sender, EventArgs e) { click++; } private void panel1_Paint(object sender, PaintEventArgs e) { } private void btnReset_Click(object sender, EventArgs e) { timer1.Stop(); txtClicks.Text = ""; txtTime.Text = ""; click = 0; } private void btnGo_Click(object sender, EventArgs e) { click = 0; timer1.Interval = int.Parse(txtTime.Text) * 1000; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { timer1.Stop(); MessageBox.Show(txtClicks.Text + " seconds up, No of clicks:" + click.ToString()); } } 
+4
source share
3 answers

except that he seems unable to count fast enough to register all mouse clicks?

maybe you should handle the DoubleClick mouse event as well as the mouse click?

+5
source

Use the MouseDown event. This will process each time and deny the need to process both Click and DoubleClick .

+7
source

I would put money on it so that some clicks go so fast that ... they count as a double click.

If you add a double-click handler and double the counter in that handler, will this give a more accurate result?

+1
source

Source: https://habr.com/ru/post/1314824/


All Articles