How to get position from Image in PictureBox

2.6k Views Asked by At

I've a question. Do someone know how I can get the position of an centered image in a Picturebox?

I need the X and Y coordinates but currently I'dn't have any idea.

Thank you in advance.

2

There are 2 best solutions below

0
On BEST ANSWER

I have solved the problem with:

_absoluteImagePositionX = imageBox.Width / 2 - image.Width / 2;
_absoluteImagePositionY = imageBox.Height / 2 - image.Height / 2;

But by the way thank you for your tips!

0
On

If picture box is bigger than image, you can try to calculate image's absolute position on the form:

int absImgX=pictureBox1.Left+pictureBox1.Width/2-pictureBox1.Image.Width/2
int absImgY=pictureBox1.Top+pictureBox1.Height/2-pictureBox1.Image.Height/2