Class GradientStopCollection

GradientStopCollection class

Represents the gradient stop collection.

public class GradientStopCollection : CollectionBase<GradientStop>

Properties

NameDescription
Capacity { get; set; }
Count { get; }
Item { get; }Gets the gradient stop by the index.
Item { get; set; }

Methods

NameDescription
Add(double, CellsColor, int)Add a gradient stop.
Add(double, Color, int)Add a gradient stop.
BinarySearch(GradientStop)
BinarySearch(GradientStop, IComparer<GradientStop>)
BinarySearch(int, int, GradientStop, IComparer<GradientStop>)
Clear()
Contains(GradientStop)
CopyTo(GradientStop[])
CopyTo(GradientStop[], int)
CopyTo(int, GradientStop[], int, int)
Exists(Predicate<GradientStop>)
Find(Predicate<GradientStop>)
FindAll(Predicate<GradientStop>)
FindIndex(Predicate<GradientStop>)
FindIndex(int, Predicate<GradientStop>)
FindIndex(int, int, Predicate<GradientStop>)
FindLast(Predicate<GradientStop>)
FindLastIndex(Predicate<GradientStop>)
FindLastIndex(int, Predicate<GradientStop>)
FindLastIndex(int, int, Predicate<GradientStop>)
GetEnumerator()
IndexOf(GradientStop)
IndexOf(GradientStop, int)
IndexOf(GradientStop, int, int)
LastIndexOf(GradientStop)
LastIndexOf(GradientStop, int)
LastIndexOf(GradientStop, int, int)
RemoveAt(int)

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Drawing;
    using System;
    using System.Drawing;

    public class DrawingClassGradientStopCollectionDemo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            try
            {
                // Create a rectangle shape with gradient fill
                var shape = worksheet.Shapes.AddShape(MsoDrawingType.Rectangle, 2, 0, 2, 0, 300, 100);
                shape.Fill.FillType = FillType.Gradient;

                // Get the GradientStopCollection from the shape's gradient fill
                GradientStopCollection gradientStops = shape.Fill.GradientFill.GradientStops;
                gradientStops.Clear();

                // Add gradient stops using both available Add methods
                gradientStops.Add(0.0, Color.Red, 255); // Opaque red at start
                gradientStops.Add(0.5, Color.Yellow, 200); // Semi-transparent yellow at middle

                // Create a CellsColor and add another gradient stop
                CellsColor customColor = workbook.CreateCellsColor();
                customColor.Color = Color.Blue;
                gradientStops.Add(1.0, customColor, 150); // Semi-transparent blue at end

                Console.WriteLine("GradientStopCollection created and populated successfully");
                workbook.Save("GradientStopCollectionDemo.xlsx");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error working with GradientStopCollection: {ex.Message}");
            }
        }
    }
}

See Also