MouseMove event triggered even if the mouse is not moving

  • Thread starter Sam Sungshik Kong
  • Start date
S

Sam Sungshik Kong

Hello!

If I understand correctly, MouseMove event is triggered when the mouse moves
(ie when point changes).
I, however, found out that it's triggered even if the mouse is not moving.

What I did was:

In an empty form, I set the Form1.Text to "0" and added the following code
for Form1.MouseMove event.

private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
int i;
i = int.Parse(this.Text);
i++;
this.Text = i.ToString();
}

I put the mouse cursor on the form and I didn't touch the mouse.
The Text (form's caption) kept increasing at irregular speed (but pretty
fast).

I thought that It could be triggered by a little shake of the mouse.
So I changed the code.

I added

private int x;
private int y;

private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (Math.Abs(e.X - x) + Math.Abs(e.Y - y) > 0)
{
int i;
i = int.Parse(this.Text);
i++;
this.Text = i.ToString();
}
x = e.X;
y = e.Y;
}


Now the Text didn't increase.

My conclusion is that the MouseMove event can be triggered even if the point
was not changed.

By the way, my mouse is MS optical mouse.

Is this by design?

Sam
 
M

Mohamoss

Hi sam
No, I don't think this is not by design I just took the code that you
posted on a new from and the counter didn't increase (except when I do move
the mouse) may be there is something else that you have in your application
that does that (or may be problem with the mouse)
Here is exactly the handler that I had
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
int i;
i = int.Parse(this.Text);
i++;
this.Text = i.ToString();

}
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top