# CustomControls Package

The **CustomControls** built-in package supplies a set of fully owner-drawn controls --- buttons, a form, a frame, a grid, a label, a slider, a textbox, and a timer --- together with the framework on which they are built. Every visible pixel is rendered by the package itself rather than by Windows, so the look and feel is identical across systems and is configured entirely through a small vocabulary of style objects ([**Fill**](/tB/Packages/CustomControls/Styles/Fill.md), [**Borders**](/tB/Packages/CustomControls/Styles/Borders.md), [**Corners**](/tB/Packages/CustomControls/Styles/Corners.md), [**TextRendering**](/tB/Packages/CustomControls/Styles/TextRendering.md), …) rather than by toggling theme flags.

![A form of the package holding one of each visible control in its default look: a frame with a gradient as a header with a label on it, labels, a text box, a slider, a grid of three rows with row headers, and two buttons with rounded corners](/Reference/Built-In/CustomControls/Images/Overview.png){:width="601" height="425"}

The package ships as two paired components: a **CustomControls DESIGNER** library --- the framework half, source-side project `CustomControls` --- that defines the rendering surface and the interface every custom control implements; and the **Custom Controls** package --- source-side project `CustomControlsPackage` --- that supplies the eight concrete `Waynes…` controls. The two are co-versioned with twinBASIC and always ship together; both are MIT-licensed.

Beyond providing ready-to-use controls, the package doubles as a worked example for authoring new custom controls. The `Waynes…` classes implement the same [**ICustomControl**](/tB/Packages/CustomControls/Framework/ICustomControl.md) interface that a hand-written control would, against the same [**CustomControlContext**](/tB/Packages/CustomControls/Framework/CustomControlContext.md) callback object and [**Canvas**](/tB/Packages/CustomControls/Framework/Canvas.md) drawing surface --- see the [Framework](/tB/Packages/CustomControls/Framework/index.md) page for the host-side contract.

```tb check_build inherits=WaynesForm
Sub New()
    btnGo.Caption = "Continue"
    btnGo.NormalState.BackgroundFill.ColorPoints.SetSolidColor vbBlue
    btnGo.NormalState.Corners.SetAll tbCurve, 12
    txtName.Value = ""
End Sub

Private Sub btnGo_Click()
    MsgBox "Hello, " & txtName.Value
End Sub
```

The controls are drawn on a [**WaynesForm**](/tB/Packages/CustomControls/WaynesForm/index.md), the package's own form, and nowhere else: on a form of the [**VB**](/tB/Packages/VB/index.md) package they are created and their properties can be set, but nothing of them is drawn. A **WaynesForm** raises no **Load** event, so the code that sets up its controls goes in the form's constructor, `Sub New`, as above (see [Setting up a form](/tB/Packages/CustomControls/WaynesForm/index.md#setting-up-a-form)). The samples on the controls' pages are written as a **WaynesForm**'s code in the same way.

## Controls

- [WaynesButton](/tB/Packages/CustomControls/WaynesButton/index.md) -- owner-drawn push-button with separate visual states for normal, hover, focused, and pressed
- [WaynesForm](/tB/Packages/CustomControls/WaynesForm/index.md) -- top-level form for hosting custom controls; exposes the **WindowsOptions** sub-object that controls the Win32 frame
- [WaynesFrame](/tB/Packages/CustomControls/WaynesFrame.md) -- rectangular container that fills its area with a configurable background
- [WaynesGrid](/tB/Packages/CustomControls/WaynesGrid/index.md) -- tabular data display with column headers, row headers, hover / selection states, and resizable columns
- [WaynesLabel](/tB/Packages/CustomControls/WaynesLabel.md) -- static text display with fill, text rendering, and caption
- [WaynesSlider](/tB/Packages/CustomControls/WaynesSlider/index.md) -- horizontal or vertical value slider with hover / focused states and a draggable block
- [WaynesTextBox](/tB/Packages/CustomControls/WaynesTextBox/index.md) -- single-line editable text field with selection, caret, surrogate-pair awareness, and inline text decorators
- [WaynesTimer](/tB/Packages/CustomControls/WaynesTimer.md) -- non-visual timer that raises a **Timer** event at a programmable interval

Every concrete control implements [**ICustomControl**](/tB/Packages/CustomControls/Framework/ICustomControl.md) and inherits a small set of layout-and-name members from an internal base class:

- All controls expose **Name**, **Left**, **Top**, **Width**, **Height**, **Anchors**, **Dock**, and **Visible**.
- Controls that can take keyboard focus ([**WaynesButton**](/tB/Packages/CustomControls/WaynesButton/index.md), [**WaynesGrid**](/tB/Packages/CustomControls/WaynesGrid/index.md), [**WaynesSlider**](/tB/Packages/CustomControls/WaynesSlider/index.md), [**WaynesTextBox**](/tB/Packages/CustomControls/WaynesTextBox/index.md)) additionally expose **TabIndex** and **TabStop**.
- [**WaynesForm**](/tB/Packages/CustomControls/WaynesForm/index.md) instead exposes form-level members: **FormDesignerId**, **Name**, position / size, and the **Controls** collection.

These members are listed on each control's own page; their definitions are identical and are not repeated separately.

> [!WARNING] BETA 1045
> A control is drawn where and as the form designer placed it for most of what code sets. Set in the form's `Sub New`, **Left**, **Height** and **Dock** take effect, and **Top**, **Width** and **Visible** do not; set while the form is shown, none of them does --- the control is not moved, resized or hidden, and no error is raised. Each property reads back the value code gave it. Place and size the controls in the form designer. A control's style objects, such as its **BackgroundFill**, are drawn as code sets them.

## Style objects

The visual style of every control is controlled by a few small helper classes, instantiated automatically through `Public WithEvents …` properties. They are nested arbitrarily --- a [**TextRendering**](/tB/Packages/CustomControls/Styles/TextRendering.md) contains a [**Fill**](/tB/Packages/CustomControls/Styles/Fill.md) for the text colour, which contains a `Granularity` and an array of `FillColorPoint` gradient stops; an array of [**Border**](/tB/Packages/CustomControls/Styles/Borders.md#border-class) objects describes how the outline of a control is stroked; and so on.

- [Anchors](/tB/Packages/CustomControls/Styles/Anchors.md) -- which sides of a control are attached to its container when the container is resized
- [Borders](/tB/Packages/CustomControls/Styles/Borders.md) -- one or more border strokes drawn around a control (including the single-stroke `Border` sub-object)
- [Corners](/tB/Packages/CustomControls/Styles/Corners.md) -- the four corner shapes and radii of a control (including the per-corner `Corner` sub-object)
- [Fill](/tB/Packages/CustomControls/Styles/Fill.md) -- the colour or gradient that paints a region (including the `FillColorPoint` / `FillColorPoints` gradient-stop sub-objects)
- [Line](/tB/Packages/CustomControls/Styles/Line.md) -- a single grid-line or resizer-bar stroke; thinner shape than a full border
- [Padding](/tB/Packages/CustomControls/Styles/Padding.md) -- per-side padding around text inside a [**TextRendering**](/tB/Packages/CustomControls/Styles/TextRendering.md)
- [TextRendering](/tB/Packages/CustomControls/Styles/TextRendering.md) -- font, padding, fill, outlines, alignment, and overflow for the text drawn inside a control (including the `FontStyle` sub-object)

Every style object raises an **OnChanged** event whenever one of its fields is set, and the control that hosts it requests a repaint on each change --- assigning style values at runtime triggers an immediate redraw. A [**WaynesFrame**](/tB/Packages/CustomControls/WaynesFrame.md) is the exception: see the WARNING on its page.

## Framework

For authoring new custom controls or forms, the **CustomControls DESIGNER** half of the package supplies:

- [_CustomControlContext](/tB/Packages/CustomControls/Framework/_CustomControlContext.md) -- the underlying COM interface of [**CustomControlContext**](/tB/Packages/CustomControls/Framework/CustomControlContext.md), defining the four callback methods: serializer access, repaint requests, timer creation, and focus changes
- [_CustomControlsCollection](/tB/Packages/CustomControls/Framework/_CustomControlsCollection.md) -- the underlying COM interface of [**CustomControlsCollection**](/tB/Packages/CustomControls/Framework/CustomControlsCollection.md), defining the collection contract: indexed access, enumeration, and add/remove
- [_CustomControlTimer](/tB/Packages/CustomControls/Framework/_CustomControlTimer.md) -- the underlying COM interface of [**CustomControlTimer**](/tB/Packages/CustomControls/Framework/CustomControlTimer.md), defining the **Interval** and **Enabled** properties
- [_CustomControlTimerEvents](/tB/Packages/CustomControls/Framework/_CustomControlTimerEvents.md) -- the event-source interface of [**CustomControlTimer**](/tB/Packages/CustomControls/Framework/CustomControlTimer.md), declaring the **OnTimer** callback that fires on each tick
- [_CustomFormContext](/tB/Packages/CustomControls/Framework/_CustomFormContext.md) -- the underlying COM interface of [**CustomFormContext**](/tB/Packages/CustomControls/Framework/CustomFormContext.md), extending **_CustomControlContext** with **Show** and **Close**
- [Canvas](/tB/Packages/CustomControls/Framework/Canvas.md) -- the drawing surface passed to **Paint**; the only way to put pixels into a custom control
- [CustomControlContext](/tB/Packages/CustomControls/Framework/CustomControlContext.md) -- callback object passed to **Initialize**; offers serializer access, repaint requests, timer creation, and focus changes
- [CustomControlTimer](/tB/Packages/CustomControls/Framework/CustomControlTimer.md) -- the timer returned by **CustomControlContext.CreateTimer**; has **Interval**, **Enabled**, and an **OnTimer** event
- [CustomControlsCollection](/tB/Packages/CustomControls/Framework/CustomControlsCollection.md) -- the **Controls** collection on a form
- [CustomFormContext](/tB/Packages/CustomControls/Framework/CustomFormContext.md) -- a **CustomControlContext** extended with **Show** and **Close** for form-class controls
- [ICustomControl](/tB/Packages/CustomControls/Framework/ICustomControl.md) -- the interface every custom control implements: **Initialize**, **Destroy**, **Paint**
- [ICustomForm](/tB/Packages/CustomControls/Framework/ICustomForm.md) -- the analogous interface for custom form classes
- [SerializeInfo](/tB/Packages/CustomControls/Framework/SerializeInfo.md) -- the per-instance serializer returned by **CustomControlContext.GetSerializer**; used to deserialize designer-set property values and to query the runtime mode

## Modules

- [Constants](/tB/Packages/CustomControls/Constants.md) -- declares the enumerations and UDTs shared across the entire **CustomControls** package; internal to the DESIGNER library

## Enumerations

- [BorderStyle](/tB/Packages/CustomControls/Enumerations/BorderStyle.md) -- window-frame style passed to [**WindowsFormOptions.BorderStyle**](/tB/Packages/CustomControls/WaynesForm/WindowsFormOptions.md#borderstyle)
- [ColorRGBA](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) -- `Long`-compatible type alias for 32-bit ABGR colour values
- [CornerShape](/tB/Packages/CustomControls/Enumerations/CornerShape.md) -- how a single corner of a control is shaped: curve, notch, or cut-out
- [Customtate](/tB/Packages/CustomControls/Enumerations/Customtate.md) -- duplicate of [**WindowState**](/tB/Packages/CustomControls/Enumerations/WindowState.md); reserved
- [DockMode](/tB/Packages/CustomControls/Enumerations/DockMode.md) -- how a control is docked inside its container
- [FillPattern](/tB/Packages/CustomControls/Enumerations/FillPattern.md) -- the gradient or fill pattern used by a [**Fill**](/tB/Packages/CustomControls/Styles/Fill.md)
- [FontWeight](/tB/Packages/CustomControls/Enumerations/FontWeight.md) -- font weights from **tbThin** through **tbHeavy**, mirroring the OpenType `wght` scale
- [PixelCount](/tB/Packages/CustomControls/Enumerations/PixelCount.md) -- `Long`-compatible type alias for measurements expressed in pixels
- [PointSize](/tB/Packages/CustomControls/Enumerations/PointSize.md) -- `Long`-compatible type alias for font sizes expressed in points
- [StartupPosition](/tB/Packages/CustomControls/Enumerations/StartupPosition.md) -- initial position of a form when it is first shown
- [TextAlignment](/tB/Packages/CustomControls/Enumerations/TextAlignment.md) -- horizontal and vertical alignment of text within a [**TextRendering**](/tB/Packages/CustomControls/Styles/TextRendering.md)
- [TextOverflowMode](/tB/Packages/CustomControls/Enumerations/TextOverflowMode.md) -- how text longer than the available area is truncated
- [WindowState](/tB/Packages/CustomControls/Enumerations/WindowState.md) -- the minimized / normal / maximized window state of a form
