-1

After moving my PictureBox around with the arrows, how would I go about using the center button to reset my PictureBox back the the center of the Form?

Overview of form

Jimi
  • 29,621
  • 8
  • 43
  • 61
shan
  • 3
  • 1
  • Do you want the car to *jump* or *move smoothly* to the center? – Jimi Mar 06 '21 at 09:07
  • Does this answer your question? [Centering controls within a form in .NET (Winforms)?](https://stackoverflow.com/questions/491399/centering-controls-within-a-form-in-net-winforms) – Peter Duniho Mar 06 '21 at 10:01
  • Move smoothly if possible but jumping is also acceptable – shan Mar 07 '21 at 09:20

1 Answers1

-1

You can put this code in the centre button click.

pictureBox.Left = (this.ClientSize.Width - pictureBox.Width) / 2 ;
pictureBox.Top = (this.ClientSize.Height - pictureBox.Height) / 2;

Or you can use pictureBox.CenterToParent();, it will position the control within the centre of the parent.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197