# StackPanel

### Introduction

The StackPanel control is a container which can be used to hold children elements which can be stacked either horizontally or vertically.

![](/files/4VZZdtODTA2SaPw4x9qS)

### Layout Requirements

Unlike other FlatRedBall.Forms controls, the StackPanel does not use a Gum runtime object from the existing project. Rather, the StackLayout is itself an invisible control which can contain other objects. Note that even though the StackLayout doesn't use a component defined in your Gum project, it still has a backing Visual object so it can be added to any other FlatRedBall.Forms object and it has full support for all Gum variables such as position and size.

### Code Example

The following code creates a StackLayout, sets it to be drawn (meaning its children will be drawn), then uses AddChild to add four buttons.

```csharp
var stackPanel = new StackPanel();
stackPanel.Visual.AddToManagers();

stackPanel.AddChild(new Button());
stackPanel.AddChild(new Button());
stackPanel.AddChild(new Button());
stackPanel.AddChild(new Button());
```

Note that the above code creates Button instances using the Button constructor. In a normal project this would instantiate the Buttons using the default Gum visual object as specified on the [DefaultFormsComponents](/flatredball/api/flatredball-forms/controls/frameworkelement/defaultformscomponents.md) static property.

### Orientation

The Orientation property sets whether children stack horizontally or vertically. The default value is Orientation.Vertical. The following code shows how to change the orientation to Horizontal.

```csharp
var stackPanel = new StackPanel();
stackPanel.Visual.AddToManagers();
stackPanel.Orientation = Orientation.Horizontal;

stackPanel.AddChild(new Button());
stackPanel.AddChild(new Button());
```

![](/files/C350X74aDO4jwvSQ9uSO)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/api/flatredball-forms/controls/stackpanel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
