Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a StackPanel-like layout in WinForms

Tags:

I created a dialog with three buttons. I put those buttons in a FlowLayoutPanel with FlowDirection set to TopDown.

I attempted to Size the buttons to the width of the panel and then set the Anchor to Left+Top+Right. This seems to have no effect in a FlowLayoutPanel.

Is there a simple solution to this? I know I can use the FlowLayoutPanel's OnResize event, and go that direction, but was hoping for a design-time setting.

like image 424
hometoast Avatar asked Mar 14 '11 14:03

hometoast


People also ask

What is stack panel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.

What is StackPanel WPF?

A StackPanel allows you to stack elements in a specified direction. By using properties that are defined on StackPanel, content can flow both vertically, which is the default setting, or horizontally.


2 Answers

You can use the TableLayoutPanel, if the explicit row management isn't too annoying.

like image 177
xod Avatar answered Dec 14 '22 23:12

xod


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

AutoScroll = True FlowDirection = TopDown WrapContents = False 

Check this for details

like image 35
Yen NQ Avatar answered Dec 15 '22 00:12

Yen NQ