I have a PictureBox (its SizeMode property set to Zoom) containing an image, and both may vary in size.
Since the user has to interact with the image directly, I need to be able to convert the PictureBox click coordinates to image coordinates.
What I have done so far, is compare the aspect ratio of the PictureBox to the aspect ratio of the image. For example, if the PictureBox is "more widescreen" in relation to the image (see screenshot), it means the PictureBox will stretch the image to its own height and center it horizontally, showing its background color (in this case red) to the left and right of the image. Then I assume the image's displayed height is the same as PictureBox.Height, and work from there.
There's a problem, though. As you can see in the screenshot (green annotation mine), the white image being stretched to fit (zoomed) inside the red PictureBox leaves a small margin at the bottom.
This doesn't happen for all PictureBox.Size / Image.Size combinations, though. This leads me to believe there must be a better way to do this.