---
title: "layoutForm"
canonical: "https://help.vicon.com/space/ShogunPost121/1253738289/layoutForm"
format: markdown
---
# Description

Dynamically positions and/or sizes the user controls managed by `controlID`. For a description of forms, see [createForm](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736701).

The form dynamically lays out all user controls anchored to it, or managed by it, based on its current size and position.

For top-level forms, the form's size and position is the bounding rectangle of the user window. For forms created using [createForm](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736701), the size and position is either set explicitly using [setControlPos](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737132), or automatically, if the form is being managed and anchored to another form.

Top-level forms automatically lay themselves out when a user window is sized and/or docked/undocked, so using [layoutForm](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738289) is unnecessary. Top-level forms only need to have this command called on them once, at the end of the creation script, after all the layout logic has been specified using [setControlAnchor](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738871). Non-top-level forms need to have layoutForm called for them if they are not being managed by another form.

## Functional area

User Window

# Command syntax

## Syntax

> Macro (scroll-tablelayout)

|  |
| --- |
| `layoutForm userControlID` |

### Arguments

| Name | Type | Required | Comments |
| --- | --- | --- | --- |
| `controlID` | int | yes | ID of form user control to lay out. |

### Flags

None

## Return value

void

## Examples

```plaintext
// Anchor two controls two each other, and to the form top-level
int $windowId; 
int $staticId, $textId;
int $formId;

// First create a User Window to place the Controls on
$windowId = `createWindow "MyWindow"`;

// Get the top-level form ID
$formId = `getTopLevelForm $windowId`;

// Create a label User Control, and add it to the form
$staticId = `createStaticBox $windowId -text "Name" -form $formId`;

// Create a Text Box Control in the window. Also add it to the
// top-level form.
$textId = `createTextBox $windowId -form $formId`;

// Attach the Static User Control to the top and to the left
// of the top-level form
setControlAnchor $staticId "left" "left" 0;
setControlAnchor $staticId "top" "top" 0;

// Make the Text Box User Control stretch from the right side
// of the Static Box, to the right side of the User Window
setControlAnchor $textId "top" "top" 0 -target $staticId;
setControlAnchor $textId "left" "right" 5 -target $staticId;
setControlAnchor $textId "right" "right" 0;

// Issue the call to lay out the top level form. We only
// need to do this once
layoutForm $formId;
```

# Additional information

## Related commands

- [createForm](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736701)
- [getControlPos](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738647)
- [getTopLevelForm](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738383)
- [setControlAnchor](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738871)
- [setControlPos](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737132)