# Framework

The framework half of the [**CustomControls**](/tB/Packages/CustomControls/index.md) package --- the interfaces, callback objects, and drawing primitives an *author* of a custom control writes against. The eight concrete `Waynes…` controls in the package are themselves built on this framework; the same pieces are available to user code that needs to implement an entirely new custom control.

A custom control:

1. Implements [**ICustomControl**](/tB/Packages/CustomControls/Framework/ICustomControl.md) (or [**ICustomForm**](/tB/Packages/CustomControls/Framework/ICustomForm.md) for a form-class custom control).
2. Stores the [**CustomControlContext**](/tB/Packages/CustomControls/Framework/CustomControlContext.md) passed to it on **Initialize** and uses it to request repaints, create timers, or change the focused element.
3. Inside **Paint**, builds one or more `ElementDescriptor` records and passes them to the [**Canvas**](/tB/Packages/CustomControls/Framework/Canvas.md) via **RuntimeUICCCanvasAddElement** --- the framework rasterises them, handles input routing, and dispatches events back through the descriptor's `AddressOf`-registered callbacks.

```tb check_build
Class MyControl
    Implements CustomControls.ICustomControl

    Private Context As CustomControls.CustomControlContext

    Private Sub OnInitialize(ByVal Ctx As CustomControls.CustomControlContext) _
            Implements CustomControls.ICustomControl.Initialize
        Set Me.Context = Ctx
    End Sub

    Private Sub OnDestroy() _
            Implements CustomControls.ICustomControl.Destroy
    End Sub

    Private Sub OnPaint(ByVal Canvas As CustomControls.Canvas) _
            Implements CustomControls.ICustomControl.Paint
        ' build ElementDescriptor records and call Canvas.RuntimeUICCCanvasAddElement
    End Sub
End Class
```

## Interfaces

- [ICustomControl](/tB/Packages/CustomControls/Framework/ICustomControl.md) -- the interface implemented by every concrete custom control: **Initialize**, **Destroy**, **Paint**
- [ICustomForm](/tB/Packages/CustomControls/Framework/ICustomForm.md) -- the analogous interface for custom form classes

## Callback objects

- [CustomControlContext](/tB/Packages/CustomControls/Framework/CustomControlContext.md) -- the callback object passed to **Initialize**; **GetSerializer**, **Repaint**, **CreateTimer**, **ChangeFocusedElement**
- [CustomFormContext](/tB/Packages/CustomControls/Framework/CustomFormContext.md) -- a **CustomControlContext** extended with **Show** and **Close**, passed to a custom form's **Initialize**
- [CustomControlTimer](/tB/Packages/CustomControls/Framework/CustomControlTimer.md) -- the timer returned by **CustomControlContext.CreateTimer**; **Interval**, **Enabled**, **OnTimer** event
- [CustomControlsCollection](/tB/Packages/CustomControls/Framework/CustomControlsCollection.md) -- the **Controls** collection on a [**WaynesForm**](/tB/Packages/CustomControls/WaynesForm/index.md) or any other custom form

## Drawing primitives

- [Canvas](/tB/Packages/CustomControls/Framework/Canvas.md) -- the drawing surface passed to **Paint**; **RuntimeUICCCanvasAddElement**, plus size and DPI accessors
- [SerializeInfo](/tB/Packages/CustomControls/Framework/SerializeInfo.md) -- the per-instance serializer returned by **CustomControlContext.GetSerializer**; **RuntimeUISrzDeserialize**, design-mode flags, owner handle, runtime mode
