Reputation: 31
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.
Upvotes: 0
Views: 2707
Reputation: 31
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!
Upvotes: 1
Reputation: 3787
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
Upvotes: 2