Center PictureBox on Form

To all,

I know this is probably and easy question but for some reason I can not get my arms around this. Maybe it is my cold or the meds :).

I have a form. On that form, I have a picurebox which is being loaded from a file which may vary in size.  When the picturebox is loaded, I have the picturebox autosize, but I want the picturebox to them center on the form.  The form is fixed and can not be maximized or minimized.

Any code and help would be greatly appreciated.

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:

        private void pictureBox1_Resize(object sender, EventArgs e)
            pictureBox1.Location = new Point(this.Width / 2 - pictureBox1.Width / 2, this.Height / 2 - pictureBox1.Height / 2);
sneeri_cAuthor Commented:
Thanks for pointing me in the right direction, Idle_Mind.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.