# Fill class
{: .no_toc }

The colour or gradient that paints a region --- background of a control, body of a border, fill of a grid line, foreground of text. A **Fill** has two parts: a [**Pattern**](#pattern) that picks the gradient direction (or `tbPatternNone` for the first colour alone), and a [**ColorPoints**](#colorpoints) collection of one or more colour stops that supply the actual colours.

A single solid colour is just a one-stop fill: call [**ColorPoints.SetSolidColor**](#setsolidcolor) with a `Long` colour, or [**SetSimplePattern**](#setsimplepattern) on the parent **Fill** for a two-colour gradient.

```tb check_build
btnGo.NormalState.BackgroundFill.ColorPoints.SetSolidColor vbBlue
btnGo.HoverState.BackgroundFill.SetSimplePattern vbBlue, vbWhite, _
        Pattern:=tbGradientNorthToSouth
```

Each stop carries a colour and a position, and both are editable in place through [**Values**](#values) after the pattern has been set. Moving the stops off 0 and 100 holds each colour longer and compresses the blend between them:

```tb check_build
With btnGo.NormalState.BackgroundFill
    .SetSimplePattern &HF3E58F, &H014C99, Pattern:=tbGradientNorthToSouth
    .ColorPoints.Values(0).PositionPercent = 20
    .ColorPoints.Values(1).PositionPercent = 80
End With
```

For three or more colour stops, build [**FillColorPoint**](#fillcolorpoint-class) instances and pass them to [**SetColorPoints**](#setcolorpoints). The stops accept fully-opaque ARGB literals (`&HFF` alpha in the high byte) --- see [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) for the encoding:

```tb check_build project=cc-private
With btnGo.NormalState.BackgroundFill
    .Pattern = tbGradientNorthToSouth
    .ColorPoints.SetColorPoints _
        New CustomControlsPackage.FillColorPoint(&HFFF3E58F, 0), _
        New CustomControlsPackage.FillColorPoint(&HFF99CCFF, 50), _
        New CustomControlsPackage.FillColorPoint(&HFF014C99, 100)
End With
```

> [!IMPORTANT]
>
> [**FillColorPoint**](#fillcolorpoint-class) is a **Private** component of the package, so
> naming it takes the **CustomControlsPackage** library symbol prefixed with an asterisk in
> *Project Settings* --- the control package, not the **CustomControls** DESIGNER library
> listed beside it --- plus the package qualifier used above. See [Exposing a library's
> private symbols](/Features/Packages/Library-Symbols.md#exposing-a-librarys-private-symbols)
> for the setting and where to find it.
>
> Note also that [**SetColorPoints**](#setcolorpoints) takes a `ParamArray` of **Variant**,
> so a call passing anything other than a [**FillColorPoint**](#fillcolorpoint-class)
> compiles and then fails at run time.

The three samples above, and a two-stop fill with a [**Granularity**](#granularity) of 6 and of 2:

![Six panels: solid blue from SetSolidColor; blue fading to white; light blue fading to brown between 20 and 80 per cent, solid above and below; three stops, light blue to light orange to brown; the same two-stop fill in six bands with Granularity 6, and in two halves with Granularity 2](/Reference/Built-In/CustomControls/Styles/Images/Fill.png){:width="617" height="349"}

* TOC
{:toc}

## Properties

### ColorPoints
{: .no_toc }

The [**FillColorPoints**](#fillcolorpoints-class) collection holding the gradient stops. Always present and pre-allocated; assigning new stops is done by calling methods on this object rather than replacing the collection.

### Pattern
{: .no_toc }

How the colours in [**ColorPoints**](#colorpoints) are mapped across the region. A member of [**FillPattern**](/tB/Packages/CustomControls/Enumerations/FillPattern.md). Default: **tbGradientNorthToSouth**. **tbPatternNone** fills the region with the first colour alone. A **Fill** with no colour stops --- a new one, such as a [**WaynesLabel**](/tB/Packages/CustomControls/WaynesLabel.md)'s **BackgroundFill** until it is given a colour --- paints nothing, and what is behind the region shows through.

## Methods

### SetSimplePattern
{: .no_toc }

Replaces the colour stops with a two-stop gradient between two solid colours, optionally adjusting the [**Granularity**](#granularity) and [**Pattern**](#pattern) at the same time. The colours are given as ordinary `Long` values (the `vb…` colour constants or a hex literal); the opaque alpha mask is OR-ed in automatically.

Syntax: *object*.**SetSimplePattern** *Value1RGB*, *Value2RGB* [, *Granularity* [, *Pattern* ] ]

*Value1RGB*
: *required* A **Long** RGB colour for the first gradient stop (position 0).

*Value2RGB*
: *required* A **Long** RGB colour for the second gradient stop (position 100).

*Granularity*
: *optional* The colour-table size assigned to [**Granularity**](#granularity). Default: 100.

*Pattern*
: *optional* A member of [**FillPattern**](/tB/Packages/CustomControls/Enumerations/FillPattern.md). Default: **tbGradientNorthToSouth**.

### SetSimplePatternRGBA
{: .no_toc }

Same as [**SetSimplePattern**](#setsimplepattern) but accepts raw 32-bit [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) values with their own alpha channels rather than three-byte RGB colours.

Syntax: *object*.**SetSimplePatternRGBA** *Value1RGBA*, *Value2RGBA* [, *Granularity* [, *Pattern* ] ]

*Value1RGBA*
: *required* A [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) (ABGR) value for the first gradient stop.

*Value2RGBA*
: *required* A [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) (ABGR) value for the second gradient stop.

*Granularity*
: *optional* The colour-table size assigned to [**Granularity**](#granularity). Default: 100.

*Pattern*
: *optional* A member of [**FillPattern**](/tB/Packages/CustomControls/Enumerations/FillPattern.md). Default: **tbGradientNorthToSouth**.

## Events

### OnChanged
{: .no_toc }

Raised whenever [**Pattern**](#pattern) is assigned or the [**ColorPoints**](#colorpoints) collection raises its own **OnChanged**.

## FillColorPoints class

The collection of [**FillColorPoint**](#fillcolorpoint-class) stops that define a [**Fill**](#)'s colour gradient. Accessed as [**Fill.ColorPoints**](#colorpoints). Internally an array of **FillColorPoint** plus a [**Granularity**](#granularity) integer.

### Granularity
{: .no_toc }

The size of the generated colour table that interpolates the stops. Higher values give smoother gradients; a value of 2 produces a hard transition between just two colours regardless of how many stops the collection holds. **Long**. Default: 100.

### Values
{: .no_toc }

The array of [**FillColorPoint**](#fillcolorpoint-class) gradient stops. Read-write, but in practice populated through the [**SetSolidColor**](#setsolidcolor), [**SetSolidColorRGBA**](#setsolidcolorrgba), [**SetColorPoints**](#setcolorpoints), or [**SetColorPointsArray**](#setcolorpointsarray) methods rather than by assigning the array directly --- assigning it needs a `FillColorPoint()`, which the project can only declare when the package is imported with an asterisk.

### SetSolidColor
{: .no_toc }

Replaces the stop array with a single fully-opaque stop. Takes a three-byte `Long` colour and OR-s in the opaque alpha mask.

Syntax: *object*.**SetSolidColor** *ValueRGB*

*ValueRGB*
: *required* A **Long** RGB colour.

### SetSolidColorRGBA
{: .no_toc }

Replaces the stop array with a single stop whose alpha is taken from the supplied value rather than forced opaque.

Syntax: *object*.**SetSolidColorRGBA** *ValueRGBA*

*ValueRGBA*
: *required* A [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) (ABGR) value.

### SetColorPoints
{: .no_toc }

Replaces the stop array with the supplied [**FillColorPoint**](#fillcolorpoint-class) values, in order.

Syntax: *object*.**SetColorPoints** *ColorPoint1* [, *ColorPoint2*, … ]

*ColorPoint1*, *ColorPoint2*, …
: *required* One or more [**FillColorPoint**](#fillcolorpoint-class) objects, passed as **Variant**s through a `ParamArray`.

### SetColorPointsArray
{: .no_toc }

Replaces the stop array with the contents of an existing array of [**FillColorPoint**](#fillcolorpoint-class).

Syntax: *object*.**SetColorPointsArray** *ColorPoints* ( )

*ColorPoints*
: *required* An array of [**FillColorPoint**](#fillcolorpoint-class). Uninitialised or empty arrays leave the collection unchanged.

### OnChanged
{: .no_toc }

Raised when the array of stops is reassigned or when any single stop raises its own **OnChanged**, or when [**Granularity**](#granularity) is assigned. The parent [**Fill**](#) listens for this event and re-raises its own.

## FillColorPoint class

A single gradient stop --- a colour together with the position (0--100 %) at which the colour applies along the gradient. Elements of the [**FillColorPoints.Values**](#values) array.

### Color
{: .no_toc }

The stop's colour as a 32-bit ABGR value. [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md).

### PositionPercent
{: .no_toc }

The stop's position along the gradient, as a percentage from 0 to 100. **Double**. A two-stop gradient typically has stops at 0 and 100; intermediate stops at 25 / 50 / 75 produce smooth multi-colour transitions.

### New
{: .no_toc }

Constructs a [**FillColorPoint**](#fillcolorpoint-class). The parameterless overload sets neither field; the two-argument overload sets both.

Syntax: **New CustomControlsPackage.FillColorPoint** [ ( *ColorRGBA*, *PositionPercent* ) ]

The package qualifier is required, and so is importing the reference with an asterisk --- see the note at the top of this page.

*ColorRGBA*
: *optional* A [**ColorRGBA**](/tB/Packages/CustomControls/Enumerations/ColorRGBA.md) value to assign to [**Color**](#color).

*PositionPercent*
: *optional* A **Double** to assign to [**PositionPercent**](#positionpercent).

### OnChanged
{: .no_toc }

Raised when either [**Color**](#color) or [**PositionPercent**](#positionpercent) is assigned. The parent [**FillColorPoints**](#fillcolorpoints-class) listens for this event.
