Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend


A FlowLayoutPanel provides a new method for laying out controls on a form. You place the FlowLayoutPanel on the form and then place controls within it. The controls flow within the FlowLayoutPanel, which would seem to be counter to the design principles most developers know and love. Consequently, many developers don’t see much use for this control. However, the FlowLayoutPanel addresses a very important need—one that will become more important as time goes on. It lets you build flexible interfaces where controls float as needed to address user needs. For example, a user who needs to use a large font will no longer experience parts of labels being hidden by text boxes, because the FlowLayoutPanel will flow the label and the text box to accommodate the larger font size.

The FlowLayoutPanel addresses a lot more than accessibility and flexibility needs. With a simple shape, you can modify the direction of a left-to-right series of controls, switching it to right-to-left. In other words, this control helps you address internationalization concerns.

Even though the FlowLayoutPanel makes your desktop application act as if it uses a standard web page with flow layout, you do have some control over the placement of controls. Simply layer the FlowLayoutPanel controls within each other, as shown in Figure 2. The layering helps you to set the overall layout of the form without defining specific positions for the controls that the form contains. This technique also helps you to group the controls so that you can move them as a unit.

Figure 2

Figure 2 Layer FlowLayoutPanel controls to achieve specific effects.

In this case, the Test button appears outside the FlowLayoutPanel controls, so you can use absolute positioning with it. FlowLayoutPanel1 contains a label and a text box. Notice that they flow left to right, as you might expect. This FlowLayoutPanel also contains FlowLayoutPanel2. Because this control is too large to fit beside the label and text box, it appears on the next line.

Within FlowLayoutPanel2 are two buttons. Notice that these buttons appear one over the other, rather than side by side. You achieve this effect by setting the FlowDirection property to TopDown. You can also set this property to RightToLeft and BottomUp. The point is that even though the controls flow, you can control their positioning somewhat.

  • + Share This
  • 🔖 Save To Your Account