65.9K
CodeProject is changing. Read more.
Home

FlowPanel

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.86/5 (7 votes)

May 18, 2003

viewsIcon

79841

downloadIcon

907

Horizontal-vertical layout control

Introduction

In many dialogs and forms I use internal panels, which simply layouts controls in one direction - vertical or horizontal. The most common example - OK, Cancel, Help buttons at the bottom (or at the right side) of a dialog. So I need an easy way to create such internal panel with vertical or horizontal layout.

Background

FlowPanel class extends UserControl functionality by providing custom layout implementation. This implementation layouts contained controls vertically or horizontally (direction must be predefined) into equal cells. Layout implementation takes into account Anchor and Dock styles (stretches controls in their cells according to these values).

Using the code

FlowPanel can be created with one line of code - constructor accepts panel name, layout direction, space size between controls, optional controls. Below is the example of horizontal panel with three buttons.

Button ok, cancel, help;
FlowPanel flow = new FlowPanel(
    FlowPanel.Orientations.Horizontal,
    5,
    ok=new Button(),
    cancel=new Button(),
    help=new Button());

Notes

When panel size is too small to fit all controls, layout implementation produces undetermined output. Maybe some kind of control shrinking could be applied in this case.