简体   繁体   中英

how to get the co-ordinates of an underlying image of a picture box

I have a picture box with an image associated with it.

The size mode of the PictureBox has been set to CenterImage

My question is how can I get the image co-ordinates for that underlying image.

Regards

I think your best bet is to calculate it yourself using a formula like this:

int xOffset = (pictureBox1.Width / 2) - (pictureBox1.Image.Width / 2);
int yOffset = (pictureBox1.Height / 2) - (pictureBox1.Image.Height / 2);

xOffset and yOffset should equal the (x,y) of the image from the top left corner of the picture box. Keep in mind, the formula above uses integer math and it could truncate values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM