rwallacej
asked on
VB.net FlowLayoutPanel - centering controls
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
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
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-LastContr ol.Locatio n.x-LastCo ntrol.Size .Width=Fre eSpaceOnTh eRightSide
the rest should be as mentioned above
Maybe it looks confusing, but I dont think there is another way. :)
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-LastContr
the rest should be as mentioned above
Maybe it looks confusing, but I dont think there is another way. :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't know why rwallacej hasn't responded, but I am positive that my solution works (have tested it and it works).
Goran
Goran
ASKER
thanks for feedback
you are welcome
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.