Solved

VB.net FlowLayoutPanel - centering  controls

Posted on 2007-04-10
7
2,479 Views
Last Modified: 2008-01-09
I've got a FlowLayoutPanel to which custom controls are added as the application runs.

Can the controls be arranged so they are CENTRED on the FlowLayoutPanel (just now they're left aligned)  - centring the controls would look better

Thanks
0
Comment
Question by:rwallacej
  • 4
7 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18885703
My initial reaction is "no"

The whole point of the flow layout is to just start laying out controls from left to right until you're done.

What you may be able to do is resize the layout panel and position it such that it appears that you've achieved centering.
0
 
LVL 18

Expert Comment

by:Priest04
ID: 18886363
Of the head, it could be done, with Padding property. If controls are of  same size, then you know how many are located in one line. Free space on the right side is easy to calculate, and you need to divide it by 2 and set such value for Panel.Padding.Left property

However, if size of controls is not the same, then my first guess is that you would be needing to loop through all controls, watch for their Location.Y property, when its the same, it means controls are on the same line. When you come to the last control

Panel.Size.Width-LastControl.Location.x-LastControl.Size.Width=FreeSpaceOnTheRightSide

the rest should be as mentioned above

Maybe it  looks confusing, but I dont think there is another way. :)
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 500 total points
ID: 18886388
one correction: in the 2nd example, where controls are not of same size, you need to set FirstControlInLine.Margin.Left, not Panel.Padding.Left, since not all lines will have the same free space on the right side

Goran
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 18

Expert Comment

by:Priest04
ID: 19264795
I don't know why rwallacej hasn't responded, but I am positive that my solution works (have tested it and it works).

Goran
0
 

Author Comment

by:rwallacej
ID: 19264885
thanks for feedback
0
 
LVL 18

Expert Comment

by:Priest04
ID: 19268050
you are welcome
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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