What it does
A nonvisual interval that raises Tick while enabled.
This is a component tray service. It appears below the form and does not take a canvas rectangle.
Set it up
- Add Timer from Toolbox.
- 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.
Put Tick on the Timer’s own script, add a Label named countLabel, set interval to 1000, and enable the Timer in the inspector or from a Button. interval must be a number.
let seconds = 0;
forma.on("Tick", () => {
seconds++;
forma.set("countLabel", "text", String(seconds));
});
Component properties
| Field | Inspector key | Editor | Accepted values / range | Runtime key |
|---|---|---|---|---|
| Interval (ms) | interval | number | 10–3600000 | interval |
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 | Enabled |
visible | boolean | Yes | Yes | Read/write | Supported runtime property. |
tag | string | Yes | Yes | Read/write | Tag |
interval | number | Yes | Yes | Read/write | Milliseconds; integer 10–3,600,000. Only fires while Timer is enabled. |
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 |
| Enabled | enabled | checkbox | — | enabled |
Events and lifecycle
Component hooks: Tick.
Tray services have lifecycle events even without a visible control. 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.
using var sample = new Forma.Core.Controls.Timer
{
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 |
|---|---|---|---|
Interval | Int32 | 1000 | Yes |
Enabled | Boolean | false | 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 | "timer" | No |
Core methods: Start(), Stop(), Dispose(), GetRenderState(), HandleRuntimeEvent(runtimeEvent), Add(child), Insert(index, child), MoveChild(child, index), Remove(child).
Core events: Tick, ChildAdded, ChildRemoved, PropertyChanged.