Sign in Join
FPDoc Onlineexperiment

TCanvas.GradientFill procedure

Member of TCanvaspublicIn unit Graphics

Fills a rectangle with a color gradient using the specified colors in a given direction.

Declaration

pascal
procedure GradientFill(ARect: TRect; AStart: TColor; AStop: TColor; 
 ADirection: TGradientDirection); virtual
 ; reintroduce

Description

GradientFill fills the area inside the specified rectangle using a color gradient with the specified start and stop colors.

No actions are performed in the method when ARect has no discernible area; both the calculated height and width for the rectangle are 0 or a negative number.

The direction for the color gradient is specified in the ADirection argument. gdVertical causes the color variations to be drawn from top to bottom in the rectangle starting with the color in AStart and ending with the color in AStop. gdHorizontal causes the color variations to be draw from left to right in the rectangle, also starting with the color in AStart and ending with the color in AStop.

GradientFill decomposes color values in AStart and AStop into their Red, Green, and Blue component values. The differences between the byte values are varied evenly in the color gradient, and drawn as colored lines oriented in the direction opposite to the color gradient. The color setting in Pen is updated, and LineTo is used to draw the number of 1 pixel lines available in the gradient direction.

Please note that the settings in Pen are not stored on entry, or restored prior to exiting from the method. The Pen color will contain the color in AStop on exit.

Use FloodFill to fill a rectangular area bounded by or filled with a specified color value. Use FillRect to fill a rectangular area with the Brush for the canvas.

See also

An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.