Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Mouse Tracking Drawing Odd Behavior
    primarykey
    data
    text
    <p>I've just made some simple code to track the mouse offset from where Mouse Down to its current position on Mouse Move within a PictureBox. I'm outputting the difference to a label and it works fine.</p> <p>So say I mousedown at X: 20 Y: 20 then move mouse left by 5. My result is X: 15 Y:20.</p> <p>Now the issue is when I take these results (diffX and diffY) and add them to an integer (testOne and testTwo). The result is exponentially different.</p> <p>Most relevant is that when I keep the mouse in the same position without moving it but just holding the button. The results continue to increase.</p> <p>I have reduced my problem to the following code:</p> <pre><code>Point startPoint = new Point(); bool dragging = false; int testOne = 30; int testTwo = 30; private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (dragging) { int diffX = (pictureBox1.PointToClient(e.Location).X - startPoint.X); int diffY = (pictureBox1.PointToClient(e.Location).Y - startPoint.Y); label9.Text = diffX.ToString(); //Works, shows desired result label10.Text = diffY.ToString(); //also works fine testOne = (testOne + diffX); //Issue here testTwo = (testTwo + diffY); //and here label11.Text = (testOne).ToString(); //Unexpected results output label12.Text = (testTwo).ToString(); } } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (!dragging) //Incase the mouse down was repeating, it's not { startPoint = pictureBox1.PointToClient(e.Location); dragging = true; } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (dragging) dragging = false; } </code></pre> <p>I'm using C# WinForms in VS 2008, Framework 3.5</p> <p>any insight would be great, maybe this is a bug or I've simply overlooked something simple. Any ideas or if you can re-produce.</p> <p>Cheers</p> <p>Craig</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload