Lewis Wilcock
Lewis Wilcock

Reputation: 61

Getting the actual top left of an image within a larger PictureBox (C# Windows Forms)

I have an PictureBox within my Windows Form. The image mode is set to Centre Image and looks like this:

enter image description here

The green rectangle shows the actual size of the PictureBox, with the blue box showing how the image is displayed because of the Centre Image mode (Which is how I want it).

My question is, how do I get a position within the image (So within the blue box), where the small red rectangle represents (0,0)?

Thanks,

Lewis

Upvotes: 0

Views: 796

Answers (1)

Steve Wellens
Steve Wellens

Reputation: 20640

You should be able to get within a pixel by calculating it:

int x = (pictureBox1.Width - pictureBox1.Image.Width) / 2;
int y = (pictureBox1.Height - pictureBox1.Image.Height) / 2;

Upvotes: 1

Related Questions