---
title: "createForm"
canonical: "https://help.vicon.com/space/Shogun16/13340092/createForm"
format: markdown
---
# Description

Creates a form user control on the given user window specified by `windowID`.

A form is an invisible rectangle that manages the size and position of other user controls. To have controls be managed by a form, use the `-form` option on the control creation command (e.g. [createTextBox](https://vicon-help.atlassian.net/wiki/spaces/Shogun16/pages/13339824)). Then use [setControlAnchor](https://vicon-help.atlassian.net/wiki/spaces/Shogun16/pages/13340137) to "anchor" the controls to the sides of the form (or to other controls). When the form gets moved or resized, the controls will automatically be re-organized according to the anchor logic specified.

Each user window has a form which can be obtained using [getTopLevelForm](https://vicon-help.atlassian.net/wiki/spaces/Shogun16/pages/13341500). Upon creation of the user window, obtain the top level form, and use it as the argument to the `-form` flag in the control creation commands.

Forms can be nested, forming hierarchies of forms to facilitate complex control layouts. The control is initially placed in the top-left corner of the user window, and must be placed by using the `-pos` option, or by using the [setControlPos](https://vicon-help.atlassian.net/wiki/spaces/Shogun16/pages/13340122) command.

The command returns the Control ID of the user control, which should be saved for later operations on the control.

## Functional area

User Window

# Command syntax

## Syntax

|  |
| --- |
| `createForm parentWindowID [-hidden] [-pos integer array] [-form integer]` |

### Arguments

| **Name** | **Type** | **Required** | **Comments** |
| --- | --- | --- | --- |
| `windowId` | int | yes | ID of user window to place the form on. |

> Macro (scroll-pagebreak)

### Flags

> Macro (scroll-tablelayout)

| **Name** | **Flag arguments** | **Argument type** | **Exclusive to** | **Comments** |
| --- | --- | --- | --- | --- |
| `pos` | 1 | integer array | — | A four element int array representing a rectangle, which specifies the initial size/position of the form relative to the top left corner of the user window. The element order is Left, Top, Right, Bottom. The default form is 200 units high x 200 units wide. |
| `form` | 1 | integer | — | Control ID of the form user control which dynamically positions this form. |
| `hidden` | 0 | — | — | — |

## Return value

integer

## Examples

```plaintext
// Create a Form User Control.
int $windowId;
int $ formId;
int$topForm;
int$controlId;
int$rect[4];
 
// First create a User Window to place the Control on
$windowId = `createWindow "MyWindow"`;
  
// Get the top level form
$topForm = `getTopLevelForm $windowId`; 
  
// Specify the size of the Form - 300x300 
$rect[0] = 20;  // Left 
$rect[1] = 20;  // Top 
$rect[2] = 320; // Right 
$rect[3] = 320; // Bottom 
  
// Create the Form, adding it as a child of the
// top level form.
$formId = `createForm $windowId -form $topForm -pos $rect`; 
  
// Now create a Text Box, and anchor it so that the text box spans
// the length of the Form
$controlId = `createTextBox $windowId -text "Text Box" -form $formId`; 
  
// Anchor it
setControlAnchor;
$controlId "top" "top" 20;
setControlAnchor; 
$controlId "left" "left" 20;
setControlAnchor; 
$controlId "right" "right" 20; 
  
// Now, call layoutForm, which will do the managing of the controls
// under the form
layoutForm $topForm;
```

# Additional information

## Related commands

- [layoutForm](https://vicon-help.atlassian.net/wiki/spaces/Shogun16/pages/13341601)
- [setControlAnchor](https://vicon-help.atlassian.net/wiki/spaces/Shogun16/pages/13340137)