What it does
The root window. Give your app somewhere to live.
Each project can contain multiple forms. Add a form with Ctrl+N; create a separate project with Ctrl+Shift+N.
Set it up
- Select your form in the designer or Solution Explorer.
- Set its Name to
samplefor the examples below. Names are case-sensitive. - Configure the component-specific properties below.
- Open the Events inspector to add a handler: methods go in event.js, imports and subscriptions in script.js. Right-click View Events or View Script to edit either file. Use View CSS for scoped styles and View Custom Properties for JSON values.
- Save sources, save the project, and open a fresh Preview. Scripts execute in Preview.
JavaScript example
These examples use supported inline subscriptions for brevity. The Events inspector can generate separate class methods in event.js instead.
Add a Label named welcomeLabel. Form startup callbacks run after all component scripts are installed. main.js is separate from the form’s own script.js.
forma.on("Load", () => {
forma.set("welcomeLabel", "text", "Let’s build something.");
});
Component properties
This component uses the shared inspector fields below; it has no additional component-specific inspector fields.
Runtime property API
Use forma.get("sample", key), forma.set("sample", key, value), or forma.bind("sample", key). Read a binding with .value; write only when the Binding column permits it. Numbers and booleans must keep their types. Arrays are passed directly, not as JSON strings.
| Key | Value type | get | set | Binding | Meaning / restrictions |
|---|---|---|---|---|---|
text | string | Yes | Yes | Read/write | Display text; use value to read live text input. |
enabled | boolean | Yes | Yes | Read/write | Supported runtime property. |
visible | boolean | Yes | Yes | Read/write | Supported runtime property. |
tag | string | Yes | Yes | Read/write | Tag |
width | number | Yes | Yes | Read/write | Configured model width; managed layouts/custom CSS can change rendered size. |
height | number | Yes | Yes | Read/write | Configured model height; managed layouts/custom CSS can change rendered size. |
minimumWidth | number | Yes | Yes | Read/write | Range 0–1600. Invalid types are rejected; numeric values clamp. |
minimumHeight | number | Yes | Yes | Read/write | Range 0–1200. Invalid types are rejected; numeric values clamp. |
maximumWidth | number | Yes | Yes | Read/write | Range 0–1600. Invalid types are rejected; numeric values clamp. |
maximumHeight | number | Yes | Yes | Read/write | Range 0–1200. Invalid types are rejected; numeric values clamp. |
backColor | string | Yes | Yes | Read/write | Background |
foreColor | string | Yes | Yes | Read/write | Foreground |
borderSides | string | Yes | Yes | Read/write | Supported runtime property. |
fontFamily | "Segoe UI" | "Arial" | "Consolas" | "Georgia" | Yes | Yes | Read/write | Font family |
fontSize | number | Yes | Yes | Read/write | Range 8–48. Invalid types are rejected; numeric values clamp. |
fontWeight | "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | Yes | Yes | Read/write | Weight |
fontStyle | "normal" | "italic" | Yes | Yes | Read/write | Font style |
textAlign | "left" | "center" | "right" | Yes | Yes | Read/write | Alignment |
lineHeight | number | Yes | Yes | Read/write | Range 0.5–4. Invalid types are rejected; numeric values clamp. |
letterSpacing | number | Yes | Yes | Read/write | Range -5–20. Invalid types are rejected; numeric values clamp. |
cssClass | string | Yes | Yes | Read/write | CSS class |
Set commands cross the native bridge asynchronously. An immediate get after set may return the previous value. Observe a binding or use the assigned value locally. Getter arrays are copies. Geometry is configured model geometry; layout and CSS may override rendered bounds.
Shared inspector fields
| Field | Inspector key | Editor | Accepted values / range | Runtime key |
|---|---|---|---|---|
| Name | name | text | — | Designer only |
| ID (read-only) | id | text | — | Designer only |
| Text / Title | text | text | — | text |
| Tag | tag | text | — | tag |
| Locked | locked | checkbox | — | Designer only |
| Background | backColor | color | — | backColor |
| Foreground | foreColor | color | — | foreColor |
| Font family | fontFamily | select | Segoe UI, Arial, Consolas, Georgia | fontFamily |
| Font size | fontSize | number | 8–48 | fontSize |
| Weight | fontWeight | select | normal, bold, 100, 200, 300, 400, 500, 600, 700, 800, 900 | fontWeight |
| Font style | fontStyle | select | normal, italic | fontStyle |
| Alignment | textAlign | select | left, center, right | textAlign |
| Line height | lineHeight | number | 0.5–4 | lineHeight |
| Letter spacing | letterSpacing | number | -5–20 | letterSpacing |
| Width | width | number | 24–1600 | width |
| Height | height | number | 20–1200 | height |
| Min width | minimumWidth | number | 0–1600 | minimumWidth |
| Min height | minimumHeight | number | 0–1200 | minimumHeight |
| Max width (0=auto) | maximumWidth | number | 0–1600 | maximumWidth |
| Max height (0=auto) | maximumHeight | number | 0–1200 | maximumHeight |
| CSS class | cssClass | text | — | cssClass |
Events and lifecycle
Component hooks: Relevant DOM events and shared lifecycle events.
Only applicable browser events fire: a control without text input will not produce native input events just because a handler is registered. Event names are case-insensitive. Put handlers on the component producing the event; a Timer Tick handler belongs to the Timer, or can be observed through forma.root.on("Tick", handler). See the event guide for payloads, validation, cleanup, and startup order.
Property-change payload
All components can report PropertyChanged for changed projected runtime properties. Handlers expose source/subscriber component handles; native DOM targets remain available. Input/Change can supply typed property values, while Click normally supplies identity without a property/value pair.
forma.on("PropertyChanged", ({ source, property, value, previousValue, origin }) => {
console.log(source.name, property, previousValue, "→", value, origin);
});
Use forma.root.on(...) to observe the active form, and event.toJSON() for portable logs. Subscriptions return unsubscribe and are cleaned up with the subscribing script.
C# example
Use this in a configured Forma C# host, not in script.js. The renderer is your host's WebView2Renderer instance.
var sample = new Forma.Core.Form
{
Name = "sample"
};
await renderer.RenderAsync(sample);
C# model reference
These are Core constructor defaults, not necessarily the Builder’s drop-time styles or size. Appearance fields belong to Builder Appearance. C# events are not all forwarded to JavaScript.
| Property | C# type | Constructor default | Writable |
|---|---|---|---|
Title | String | "" | Yes |
Width | Int32 | 1366 | Yes |
Height | Int32 | 768 | Yes |
Name | String | null | Yes |
LayoutSlot | Int32 | 1 | Yes |
X | Nullable1` | null | Yes |
Y | Nullable1` | null | Yes |
Text | String | null | Yes |
Value | String | null | Yes |
Placeholder | String | null | Yes |
Label | String | null | Yes |
ControlType | String | "form" | No |
Core methods: GetRenderState(), HandleRuntimeEvent(runtimeEvent), Add(child), Insert(index, child), MoveChild(child, index), Remove(child).
Core events: ChildAdded, ChildRemoved, PropertyChanged.