Solved

VB.net FlowLayoutPanel - centering  controls

Posted on 2007-04-10
7
2,520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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