Visual C#

Accessories for Control Design: The Flow Layout Panel

To further assist you with application design, the .NET Framework provides the flow layout panel that you can use instead of manually positioning your…

2 min read425 words

Introduction#

To facilitate better application layout, the .NET Framework includes the flow layout panel as an alternative to the manual positioning of controls either horizontally or vertically. When configured for horizontal use, the panel automatically aligns controls to maintain a consistent distance from the container's top edge. This alignment only affects controls residing within that specific container. The .NET Framework represents this via the FlowLayoutPanel class, and the FlowLayoutPanel object is available in the Toolbox. To use it, simply select it from the Toolbox and add it to the form, where it appears as a dotted rectangular area:

After placing it on a form, you can add controls to it. To do this, you would click a control from the Toolbox and click inside the flow layout panel. When you add the first control, it gets positioned in the top left side of the container and you cannot move it to a different position (if this were done it would deceive the purpose of the flow layout panel):

When you add a second control to the flow layout panel, it is positioned on the right side of the previously added control with the same horizontal alignment. You can continue adding other controls. If you want the controls to be aligned vertically, resize the flow layout panel accordingly:

If you need to arrange controls vertically rather than horizontally, you can adjust the flow layout panel by making it narrower and increasing its height:

In the same way, if the flow layout panel is narrow and the controls are positioned vertically, if you enlarge it, its control would be positioned horizontally. As you can see, the flow layout panel provides a convenient way of aligning controls.

Characteristics of the Flow Layout Panel#

It was previously established that the first control placed in a flow layout panel is situated at the top-left, with following controls added to the right or below. This default left-to-right behavior can be changed if your design requires a right-to-left flow. The FlowDirection property, an enumeration, handles this, defaulting to LeftToRight. Setting it to RightToLeft places the first control at the top-right, with others following to its left. When a control is added to the panel, it defaults to the top-left, and subsequent controls fill the space to the right. If space is insufficient, controls wrap to the next row. Resizing the panel can lead to vertical alignment. This wrapping capability is managed by the WrappingContents Boolean property, which is True by default and works with the FlowDirection setting. Home Copyright © 2010-2011 C#Key