winforms - C# Mouse Tracking Drawing Odd Behavior -


I have just created a few simple codes to track mouse offset from where the mouse in your current position Moves into the picture box. I am outputting a label's difference and it works fine.

So say I like nests in X Location: 20 Y: 20 then left from mouse 5. My result is X: 15 Y: 20.

Now this problem occurs when I take these results (diffX and diffY) and add them to an integer (testOne and testTwo). The result is fast different.

The most relevant is that when I place the mouse in no place, but press the button. The results continue to grow.

I have reduced my problem in the following code:

  point startpoint = new point (); Bool dragging = false; Int testOne = 30; Int testTwo = 30; Private Zero Picture Box 1_MouseMove (Object Sender, Mouse Event Ergus E) {If (Drag) {Int diffX = (PhotoBox 1 pointpointlient (E. location) .X - startPoint.X); Int diffY = (pictureBox1.PointToClient (e.Location) .Y - startPoint.Y); Label 9 Text = diffX.ToString (); // Works, shows the desired result 10. Text = diffY.ToString (); // also works fine testOne = (testOne + diffX); // test.two points here (testTwo + diffY); // and label 11 here Text = (testOne) .ostring (); // Unexpected results output label 12. Text = (test two). Ostring (); }} Private Zero Image Box 1_MouseDown (Object Sender, MouseEventArgs E) {If (dragging!) // was repeated by pressing the mouse down, this is not {startPoint = pictureBox1.PointToClient (E. location); Drag = true; }} Private Zero Image Box 1_MouseUp (Object Sender, MouseEventArgs E) {If (Dragging) Dragging = False; }   

I v. s. Framework 3.5

Any information will be great, maybe it's a bug or I'm just a bit simpler. Any ideas or if you can reproduce.

Cheers

Craig

It seems as though You want to subtract the current point from the starting point, not the last point. Set the startpoint at the end of your seasonal function at the current point.

  startPoint = pictureBox1.PointToClient (E. location);    

Comments