COMPONENT REFERENCERoot window

Form

The root window. Give your app somewhere to live.

kind: formJavaScript + C#Implemented

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

  1. Select your form in the designer or Solution Explorer.
  2. Set its Name to sample for the examples below. Names are case-sensitive.
  3. Configure the component-specific properties below.
  4. 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.
  5. 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.

KeyValue typegetsetBindingMeaning / restrictions
textstringYesYesRead/writeDisplay text; use value to read live text input.
enabledbooleanYesYesRead/writeSupported runtime property.
visiblebooleanYesYesRead/writeSupported runtime property.
tagstringYesYesRead/writeTag
widthnumberYesYesRead/writeConfigured model width; managed layouts/custom CSS can change rendered size.
heightnumberYesYesRead/writeConfigured model height; managed layouts/custom CSS can change rendered size.
minimumWidthnumberYesYesRead/writeRange 0–1600. Invalid types are rejected; numeric values clamp.
minimumHeightnumberYesYesRead/writeRange 0–1200. Invalid types are rejected; numeric values clamp.
maximumWidthnumberYesYesRead/writeRange 0–1600. Invalid types are rejected; numeric values clamp.
maximumHeightnumberYesYesRead/writeRange 0–1200. Invalid types are rejected; numeric values clamp.
backColorstringYesYesRead/writeBackground
foreColorstringYesYesRead/writeForeground
borderSidesstringYesYesRead/writeSupported runtime property.
fontFamily"Segoe UI" | "Arial" | "Consolas" | "Georgia"YesYesRead/writeFont family
fontSizenumberYesYesRead/writeRange 8–48. Invalid types are rejected; numeric values clamp.
fontWeight"normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900"YesYesRead/writeWeight
fontStyle"normal" | "italic"YesYesRead/writeFont style
textAlign"left" | "center" | "right"YesYesRead/writeAlignment
lineHeightnumberYesYesRead/writeRange 0.5–4. Invalid types are rejected; numeric values clamp.
letterSpacingnumberYesYesRead/writeRange -5–20. Invalid types are rejected; numeric values clamp.
cssClassstringYesYesRead/writeCSS 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

FieldInspector keyEditorAccepted values / rangeRuntime key
Namenametext—Designer only
ID (read-only)idtext—Designer only
Text / Titletexttext—text
Tagtagtext—tag
Lockedlockedcheckbox—Designer only
BackgroundbackColorcolor—backColor
ForegroundforeColorcolor—foreColor
Font familyfontFamilyselectSegoe UI, Arial, Consolas, GeorgiafontFamily
Font sizefontSizenumber8–48fontSize
WeightfontWeightselectnormal, bold, 100, 200, 300, 400, 500, 600, 700, 800, 900fontWeight
Font stylefontStyleselectnormal, italicfontStyle
AlignmenttextAlignselectleft, center, righttextAlign
Line heightlineHeightnumber0.5–4lineHeight
Letter spacingletterSpacingnumber-5–20letterSpacing
Widthwidthnumber24–1600width
Heightheightnumber20–1200height
Min widthminimumWidthnumber0–1600minimumWidth
Min heightminimumHeightnumber0–1200minimumHeight
Max width (0=auto)maximumWidthnumber0–1600maximumWidth
Max height (0=auto)maximumHeightnumber0–1200maximumHeight
CSS classcssClasstext—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.

PropertyC# typeConstructor defaultWritable
TitleString""Yes
WidthInt321366Yes
HeightInt32768Yes
NameStringnullYes
LayoutSlotInt321Yes
XNullable1`nullYes
YNullable1`nullYes
TextStringnullYes
ValueStringnullYes
PlaceholderStringnullYes
LabelStringnullYes
ControlTypeString"form"No

Core methods: GetRenderState(), HandleRuntimeEvent(runtimeEvent), Add(child), Insert(index, child), MoveChild(child, index), Remove(child).

Core events: ChildAdded, ChildRemoved, PropertyChanged.

Search components, properties, and guides.

↑↓ navigate Enter open Esc close