?
Solved

VB.net FlowLayoutPanel - centering  controls

Posted on 2007-04-10
7
Medium Priority
?
2,599 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 2000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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