C# Center panel help

Discuss anything programming related.
Post Reply
User avatar
Zaid
Posts: 250
Joined: Sun Jan 09, 2011 2:07 am

C# Center panel help

Post by Zaid »

Okay I have two panels panel1 and panel2, I have put panel2 inside of panel1 and I centered it with this.

Code: Select all

panel2.Location = new Point(panel1.Width / 2 - panel2.Width / 2,panel1.Height / 2 - panel2.Height / 2);
I enabled panel1's Autoscroll.
The AutoScroll works for when panel2's X or Y is greater than panel1's Width or Height, But when panel2's location is -100,-100, Half of panel2 is cut off.
That might be really confusing.

Soo, Basically the auto scroll works perfect when panel2 is smaller than panel1 but when panel2 is bigger than panel1 panel2's center is in the corner so all I see is everything from the center all the way down and the center all the way to the right, lol CONFUSING.
Oh well, If you can help that would be great!
User avatar
OwnZ joO
Posts: 1197
Joined: Sun Dec 09, 2007 4:46 pm

Re: C# Center panel help

Post by OwnZ joO »

I'm not exactly sure what you're trying to do, but I would mess with anchor or dock settings. If you set the Dock property of the panel inside the other panel to DockStyle.Fill and set the Padding of the outside panel then it will have the amount of padding between the outside one and the inside one. Which can allow you to center it if you have an equal amount of padding on left and right sides.
Post Reply