1

The resolution of image is 4000x7000 and size of picture box is 500x600.

private void pictureBoxZoom_Click(object sender, EventArgs e)
{
    MouseEventArgs me = (MouseEventArgs)e;

    string message = "X=" 
        + (image.Width * me.X / pictureBox1.Width) 
        + ", Y=" 
        + (image.Height * me.Y / pictureBox1.Height);

    MessageBox.Show(message);
}
jamesnet214
  • 1,044
  • 13
  • 21

1 Answers1

0

As the picturebox size mode property is set to centerImage. We can calculate the centre coordinates of the image. After getting the centre coordinates we can subtract mouse location from half the size of picture box and we will get the desired result. I have added padding as well into the calculations as in my case when I would centre the image the pictures gets some padding as well. In my case I had to divide the paddings with 2, but I have removed that from here as I'm not sure if that would be the case for everyone.

point.X = ((pictureBoxZoom.Image.Width / 2) + (pictureBoxZoom.Padding.Right) - (pictureBoxZoom.Padding.Left) - ((pictureBoxZoom.Width / 2) - me.X));

point.Y = ((pictureBoxZoom.Image.Height / 2) - (pictureBoxZoom.Padding.Top) + (pictureBoxZoom.Padding.Bottom) - ((pictureBoxZoom.Height / 2) - me.Y));