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 : IShapeCollectionProperties
| Property | Type | Access | Description |
|---|---|---|---|
Count | int | Read | Number of shapes in the collection. |
ParentGroup | IGroupShape? | Read | Parent group shape, if this collection belongs to a group. |
Methods
AddAutoShape(ShapeType, float, float, float, float)
Add an auto shape to the slide.
| Parameter | Type | Description |
|---|---|---|
shapeType | ShapeType | Shape type (e.g., ShapeType.Rectangle). |
x | float | X position in points. |
y | float | Y position in points. |
width | float | Width in points. |
height | float | Height 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.
| Parameter | Type | Description |
|---|---|---|
shapeType | ShapeType | Typically ShapeType.Rectangle. |
x | float | X position. |
y | float | Y position. |
width | float | Width. |
height | float | Height. |
image | IPPImage | Image to embed. |
Returns: IPictureFrame
AddTable(float, float, double[], double[])
Add a table to the slide.
| Parameter | Type | Description |
|---|---|---|
x | float | X position. |
y | float | Y position. |
columnWidths | double[] | Width of each column. |
rowHeights | double[] | 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);