positioning panels on form

msmeth
10-16-2006, 05:14 PM
Hi everyone.

Please excuse the cross-post. I accidentally posted this in the Legacy VB section, but I'm actually using .NET.... :rolleyes:

Anyway, here goes:

I have 5 panels on a form (this number can vary but the size of all the panels are the same) and I need to position them across the top of my windows form. The panels were created programmatically and I am positioning them via code also to allow for resizing.

I need one panel in the leftmost corner, one in the rightmost corner, and the remaining panels evenly spaced in between those two. I can't figure out an algorithm for this and am really hoping one of you can help me out. Thanks in advance.

Stigi
10-17-2006, 04:10 AM
What about the sizes on the panels? Are they all gonna have 20% width? or do some have fixed width?

Iceplug
10-17-2006, 04:15 AM
Each panel has the same width?

The first panel's .Left goes to 0 (its leftmost)
The last panel's .Left should be F.ClientSize.Width - panel.width (F is the form, probably Me)
Therefore the other three panels should be evenly distributed from 0 to F.ClientSize.Width - panel.width.
Since you have three panels left over, you just have to subdivide the range into fours (accounts for the first one):
That means you take F.ClientSize.Width - panel.width and divide it by 4.

Next, you multiply by 1, 2, and 3 to get the panel locations:
panel1 .Left is F.ClientSize.Width - panel.width / 4
panel2 .Left is 2 * panel1. Left
panel3 is 3 * panel1
:)

msmeth
10-17-2006, 10:56 AM
Thank you! I was missing first panel. I kept dividing by 3 for the remaining panels instead of 4. Much thanks. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum