ShapeCollection — Aspose.Slides FOSS for .NET API Reference

The ShapeCollection class holds all shapes on a slide. Access it via Slide.Shapes. It provides factory methods for adding auto shapes, connectors, picture frames, and tables.

Package: Aspose.Slides.Foss (net9.0)

using Aspose.Slides.Foss;
public class ShapeCollection : IShapeCollection

Properties

PropertyTypeAccessDescription
CountintReadNumber of shapes in the collection.
ParentGroupIGroupShape?ReadParent group shape, if this collection belongs to a group.

Methods

AddAutoShape(ShapeType, float, float, float, float)

Add an auto shape to the slide.

ParameterTypeDescription
shapeTypeShapeTypeShape type (e.g., ShapeType.Rectangle).
xfloatX position in points.
yfloatY position in points.
widthfloatWidth in points.
heightfloatHeight in points.

Returns: IAutoShape

InsertAutoShape(int, ShapeType, float, float, float, float)

Insert an auto shape at a specific index.

AddConnector(ShapeType, float, float, float, float)

Add a connector shape.

Returns: IConnector

AddPictureFrame(ShapeType, float, float, float, float, IPPImage)

Add a picture frame with an embedded image.

ParameterTypeDescription
shapeTypeShapeTypeTypically ShapeType.Rectangle.
xfloatX position.
yfloatY position.
widthfloatWidth.
heightfloatHeight.
imageIPPImageImage to embed.

Returns: IPictureFrame

AddTable(float, float, double[], double[])

Add a table to the slide.

ParameterTypeDescription
xfloatX position.
yfloatY position.
columnWidthsdouble[]Width of each column.
rowHeightsdouble[]Height of each row.

Returns: ITable

Reorder(int, IShape)

Move a shape to a new z-order index.

Remove(IShape)

Remove a shape from the collection.

RemoveAt(int)

Remove the shape at the specified index.

IndexOf(IShape)

Return the index of a shape.

ToArray()

Return all shapes as an array.

Clear()

Remove all shapes from the collection.


Usage Examples

Add Shapes to a Slide

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];

// Add a rectangle
var rect = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 200, 100);
rect.AddTextFrame("Hello");

// Add an ellipse
slide.Shapes.AddAutoShape(ShapeType.Ellipse, 300, 50, 100, 100);

Console.WriteLine($"Shape count: {slide.Shapes.Count}");
prs.Save("shapes.pptx", SaveFormat.Pptx);

Add a Table

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var slide = prs.Slides[0];

double[] colWidths = { 100, 150, 150 };
double[] rowHeights = { 30, 30, 30 };
var table = slide.Shapes.AddTable(50, 50, colWidths, rowHeights);

prs.Save("table.pptx", SaveFormat.Pptx);

See Also