An easy stack layout panel for WinForms

This is a simple, but useful tip. Users of WPF are spoiled. They have all sorts of layout options. Those of us still working in WinForms have FlowLayoutPanel and TableLayoutPanel. That’s it. WPF has those and more.

For my current project, I needed a panel to layout controls vertically. The TableLayoutPanel can be awkward to work with, at least for what I need it to. At first glance, the FlowLayoutPanel looks it won’t work, since it produces something like this:

FlowLayoutTable_1

That’s with changing the FlowDirection to TopDown and putting AutoScroll to true.

But what I want is this:

image

To achieve this layout, merely set all the following properties on a FlowLayoutPanel:

  • AutoScroll = True
  • FlowDirection = TopDown
  • WrapContents = False

et voilà, Instant stack panel.

3 thoughts on “An easy stack layout panel for WinForms

  1. John Gietzen

    Ah, brilliant. Thanks.

    It looks like AutoSize instead of AutoScroll also works, which allows you to have the “real” version of stack panel, which can then be wrapped inside of *something else* with auto scroll, as well.

  2. Pingback: ¿Cómo emular un StackPanel de WPF en Windows Forms? - c# windows-forms - Preguntas/Respuestas

Comments are closed.