Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The mathematics in your mouse-move handler for moving the rectangle based on the mouse-movements seems quite off; I think you want something like this:</p> <pre><code>private void Image_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { int initialX = 0, initialY = 0; // for example. Rectangle.X = (e.X - FirstPoint.X) + initialX; Rectangle.Y = (e.Y - FirstPoint.Y) + initialY; Image.Invalidate(); } } </code></pre> <p>This way, the rectangle's upper left corner will follow the mouse by tracking the delta between the <em>initial</em> mouse-down location and the <em>current</em> mouse location. Note however that each time you re-click and drag, the rectangle will move back to its <em>original</em> location.</p> <p>If, instead, you want the Rectangle to 'remember' its position across multiple click-and-drag operations (i.e. not to be reinitialized to its initial location on mouse-down) you can do:</p> <pre><code>private void Image_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { // Increment rectangle-location by mouse-location delta. Rectangle.X += e.X - FirstPoint.X; Rectangle.Y += e.Y - FirstPoint.Y; // Re-calibrate on each move operation. FirstPoint = new MovePoint { X = e.X, Y = e.Y }; Image.Invalidate(); } } </code></pre> <p>One other suggestion: There's no need to create your own <code>MovePoint</code> type when there's already the <code>System.Drawing.Point</code> type. Also, in general, try not to create mutable structs.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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