The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
Row

GradientFill Interface

Contains characteristics required to create a gradient fill.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.2.Core.dll

Declaration

public interface GradientFill
Public Interface GradientFill
public interface GradientFill
Public Interface GradientFill
public interface GradientFill
Public Interface GradientFill

Remarks

An object that exposes the GradientFill is available via the Fill.Gradient property.

Use the GradientFill.Type to specify a gradient type and set properties based on the selected type. To create a linear gradient, the GradientFill.Degree and the GradientFill.Stops properties are required. For the path gradient, specify the GradientFill.Stops, GradientFill.RectangleLeft, GradientFill.RectangleRight, GradientFill.RectangleTop and the GradientFill.RectangleBottom properties.

This example demonstrates how to fill a cell background with a color gradient of the linear type. Use the Formatting.Fill property to access the Fill object that specifies the background fill of a cell or a range. Specify the Fill.FillType to the FillType.Gradient type and specify the gradient characteristics - tilt and two color stops. Only two color stops with positions of 0 and 1 are currently supported.

// Specify a linear gradient fill for a cell.
Fill fillA1 = worksheet.Cells["A1"].Fill;
fillA1.FillType = FillType.Gradient;
fillA1.Gradient.Type = GradientFillType.Linear;
// Set the tilt for the gradient line in degrees.
// 90 degree angle defines a color transition from the top to the bottom.
fillA1.Gradient.Degree = 90;
// Specify two gradient colors. 
// The position of a color stop should be either 0 (start) or 1 (end).
fillA1.Gradient.Stops.Add(0, Color.Yellow);
fillA1.Gradient.Stops.Add(1, Color.SkyBlue);

// Specify a linear gradient fill for a range.
worksheet.Range["C3:F8"].Fill.FillType = FillType.Gradient;
GradientFill rangeGradient1 = worksheet.Range["C3:F8"].Fill.Gradient;
rangeGradient1.Type = GradientFillType.Linear;
// Set the tilt for the gradient line in degrees.
// 45 degree angle defines a color transition from top left to bottom right.
rangeGradient1.Degree = 45;
// Specify two gradient colors. 
// The position of a color stop should be either 0 (start) or 1 (end).
GradientStopCollection rangeStops1 = rangeGradient1.Stops;
rangeStops1.Add(0, Color.BlanchedAlmond);
rangeStops1.Add(1, Color.Blue);

This example demonstrates how to fill a cell background with a color gradient of the path type. Use the Formatting.Fill property to access the Fill object that specifies the background fill of a cell or a range. Specify the Fill.FillType to the GradientFillType.Path type and specify the gradient characteristics - convergence and two color stops. Only two color stops with positions of 0 and 1 are currently supported.

To create a gradient with a shading style "From center" (MS Excel term), set all convergence positions (left, right, top, bottom) to 0.5, as illustrated in the following example.

// Specify a path gradient fill for a cell.
Fill fillB1 = worksheet.Cells["A3"].Fill;
fillB1.FillType = FillType.Gradient;
GradientFill cellGradient = fillB1.Gradient;
cellGradient.Type = GradientFillType.Path;
// Set the relative position of a convergence point.
cellGradient.RectangleLeft = 0f;
cellGradient.RectangleRight = 0f;
cellGradient.RectangleTop = 0.5f;
cellGradient.RectangleBottom = 0.5f;
// Specify two gradient colors. 
// The position of a color stop should be either 0 (start) or 1 (end).
GradientStopCollection cellStops2 = cellGradient.Stops;
cellStops2.Add(0, Color.Yellow);
cellStops2.Add(1, Color.Red);

// Specify a path gradient fill for a range.
worksheet.Range["C13:F18"].Fill.FillType = FillType.Gradient;
GradientFill rangeGradient2 = worksheet.Range["C13:f18"].Fill.Gradient;
rangeGradient2.Type = GradientFillType.Path;
// Set the relative position of a convergence point.
rangeGradient2.RectangleLeft = 0.5f;
rangeGradient2.RectangleRight = 0.5f;
rangeGradient2.RectangleTop = 0.5f;
rangeGradient2.RectangleBottom = 0.5f;
// Specify two gradient colors. 
// The position of a color stop should be either 0 (start) or 1 (end).
GradientStopCollection rangeStops2 = rangeGradient2.Stops;
rangeStops2.Add(0, Color.Orange);
rangeStops2.Add(1, Color.Green);
See Also