AB4D Forum
Bitmap coordinates on mouse move or click - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: ZoomPanel (https://forum.ab4d.com/forumdisplay.php?fid=8)
+--- Thread: Bitmap coordinates on mouse move or click (/showthread.php?tid=36)



Bitmap coordinates on mouse move or click - cjlindstrom - 05-03-2010

I have a need for a viewer that will allow me to shot an image and when in the mouse move event I want to track the actual bitmap pixel coordinate no matter what zoom level or pan position. So I guess I need to translate mouse location to image pixel. Can you do that with your zoom panel?

Thanks,
Craig


RE: Bitmap coordinates on mouse move or click - abenedik - 05-06-2010

This is very easy to do.

Check out the Painter sample that comes with ZoomPanel.

Here user can draw lines on a Canvas named PaintCanvas.
On PaintCanvas's left mouse down event handler the coordinates of the mouse on the PaintCanvas are get with:
Code:
private void PaintCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
        Point startPoint;

        startPoint = e.GetPosition(PaintCanvas);

The startPoint is the actual point on the canvas - the same point/pixel will always have the same coordinates regardless of the applied zoom and panning.