I am trying to draw a rectangle on top of an image when I hold right click and move the mouse across the image. At the moment of the mouse click a boolean is changed to true and when the mouse move event occurs and the bool is true, I have the next code:
// currMouselocation - the current mouse location rightClickTrackLocation - the point where the user right clicked
trackRect.Visibility = Visibility.Visible;//making the rectangle visible
var xPos = Math.Min(currMouselocation.X, rightClickTrackLocation.X);
var yPos = Math.Min(currMouselocation.Y, rightClickTrackLocation.Y);
var w = Math.Max(currMouselocation.X, rightClickTrackLocation.X) - xPos;
var h = Math.Max(currMouselocation.Y, rightClickTrackLocation.Y) - yPos;
trackRect.Width = w;
trackRect.Height = h;
Canvas.SetLeft(trackRect, xPos);
Canvas.SetTop(trackRect, yPos);
The problem is that the Rectangle is drawn from the center of the image and not from the clicked point.