1

I'm placing some pictureboxes with coordinates

pictureBox.Location = new Point(x, y);

if i choose the coordinates 75,40 the picturebox appears in that coordinates but in the left corner, I want the picturebox appears in 75,40 centered. like this: enter image description here

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
wozzarvl
  • 304
  • 4
  • 17

1 Answers1

3

That is simple, you just have to subtract the position that you want by the size of the pictureBox and divide it by 2.

So, instead of this

pictureBox.Location = new Point(x, y);

You want this

pictureBox.Location = new Point(x - pictureBox.Size.Width/2, y - pictureBox.Size.Height/2);
Miguel71
  • 68
  • 5