Solved

Center PictureBox on Form

Posted on 2006-11-16
2
477 Views
Last Modified: 2008-01-09
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.

Thanks
0
Comment
Question by:sneeri_c
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 17961054
Try...

        private void pictureBox1_Resize(object sender, EventArgs e)
        {
            pictureBox1.Location = new Point(this.Width / 2 - pictureBox1.Width / 2, this.Height / 2 - pictureBox1.Height / 2);
        }
0
 

Author Comment

by:sneeri_c
ID: 17961843
Thanks for pointing me in the right direction, Idle_Mind.

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 48
designing in object programming 12 79
Keyboard 2 34
Unable to connect C# program to an SQL database - Exception occurs. 4 22
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question