windowsforms-devexpress-dot-utils-dot-layout.md
A panel that arranges its child elements in a single line, either vertically or horizontally.
Namespace : DevExpress.Utils.Layout
Assembly : DevExpress.Utils.v25.2.dll
NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core
public class StackPanel :
XtraLayoutPanelBase,
IStackPanel,
IXtraLayoutPanel
Public Class StackPanel
Inherits XtraLayoutPanelBase
Implements IStackPanel,
IXtraLayoutPanel
The Stack Panel arranges its child controls in one of four directions depending on the StackPanel.LayoutDirection setting. The figure below illustrates a top-to-bottom layout.
To populate a panel at design time, drag and drop controls onto the panel. You can drag child panel elements to re-arrange them.
To populate a stack panel in code, add elements to the panel’s Controls collection.
stackPanel1.Controls.Add(this.labelControl6);
stackPanel1.Controls.Add(this.textEdit5);
stackPanel1.Controls.Add(this.labelControl5);
stackPanel1.Controls.Add(this.textEdit6);
stackPanel1.Controls.Add(this.labelControl4);
stackPanel1.Controls.Add(this.textEdit8);
stackPanel1.Controls.Add(this.labelControl3);
stackPanel1.Controls.Add(this.textEdit9);
stackPanel1.Controls.Add(this.simpleButton5);
stackPanel1.Controls.Add(this.simpleButton6);
stackPanel1.LayoutDirection = DevExpress.Utils.Layout.StackPanelLayoutDirection.TopBottom;
stackPanel1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 0);
stackPanel1.Controls.Add(Me.labelControl6)
stackPanel1.Controls.Add(Me.textEdit5)
stackPanel1.Controls.Add(Me.labelControl5)
stackPanel1.Controls.Add(Me.textEdit6)
stackPanel1.Controls.Add(Me.labelControl4)
stackPanel1.Controls.Add(Me.textEdit8)
stackPanel1.Controls.Add(Me.labelControl3)
stackPanel1.Controls.Add(Me.textEdit9)
stackPanel1.Controls.Add(Me.simpleButton5)
stackPanel1.Controls.Add(Me.simpleButton6)
stackPanel1.LayoutDirection = DevExpress.Utils.Layout.StackPanelLayoutDirection.TopBottom
stackPanel1.Padding = New System.Windows.Forms.Padding(0, 10, 0, 0)
You can stretch a control to make it occupy all the available space in a stack panel. To do this at design time, enable the control’s Stretched extension property. In the figure below, a TextEdit control between two SimpleButtons is stretched.
To do that in code, call the StackPanel.SetStretched(Control, Boolean) method and pass the required control as the first method parameter.
stackPanel3.SetStretched(textEdit10, true);
stackPanel3.SetStretched(textEdit10, True)
To limit the size of a stretched control, use its MaximumSize value.
Note
The Stretched extender property is ignored in auto-size mode.
The StackPanel can automatically adjust its size to fit its contents. Use the following properties to enable the panel’s auto-size mode:
Tip
You can also enable the auto-size functionality for controls within the StackPanel and for containers (for example, a form) where the StackPanel resides.
Example
The following example enables the auto-size functionality for the panel and the form that contains this panel. The code also adds an empty space around the panel via the Padding setting.
private void Form1_Load(object sender, EventArgs e) {
this.AutoSize = true;
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
stackPanel1.Dock = DockStyle.Fill;
stackPanel1.Padding = new Padding(10);
stackPanel1.AutoSize = true;
stackPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AutoSize = True
Me.AutoSizeMode = AutoSizeMode.GrowAndShrink
StackPanel1.Dock = DockStyle.Fill
StackPanel1.Padding = New Padding(10)
StackPanel1.AutoSize = True
StackPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink
End Sub
Note
The Stretched extender property is ignored in auto-size mode.
Show 11 items
Object MarshalByRefObject Component Control ScrollableControl XtraScrollableControl XtraPanel DevExpress.Utils.Controls.PanelBase PanelControl XtraLayoutPanelBase StackPanel
See Also