Solved

VB.net FlowLayoutPanel - centering  controls

Posted on 2007-04-10
7
2,368 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Expert Comment

by:Priest04
Comment Utility
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
Comment Utility
thanks for feedback
0
 
LVL 18

Expert Comment

by:Priest04
Comment Utility
you are welcome
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now