Working with Connectors — Aspose.Slides FOSS for .NET

This guide shows how to add and configure connectors between shapes in PowerPoint presentations using Aspose.Slides FOSS for .NET. Connectors are shapes that visually link two other shapes with a line; the library supports bent, straight, and curved connector types. The connection points on a shape are identified by integer connection site indexes.


Connection Site Indexes

Each shape exposes four standard connection sites:

IndexSide
0Top
1Left
2Bottom
3Right

Adding a Bent Connector Between Two Shapes

Call slide.Shapes.AddConnector() with a ShapeType, then set StartShapeConnectedTo and EndShapeConnectedTo with connection site indexes to wire two shapes with a bent connector:

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

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

// Create two shapes to connect
var box1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 150, 150, 60);
box1.AddTextFrame("Start");

var box2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 400, 150, 150, 60);
box2.AddTextFrame("End");

// Add a bent connector (position/size are ignored once connected)
var conn = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);

// Connect right side of box1 to left side of box2
conn.StartShapeConnectedTo = box1;
conn.StartShapeConnectionSiteIndex = 3;   // right
conn.EndShapeConnectedTo = box2;
conn.EndShapeConnectionSiteIndex = 1;     // left

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

Connector Shape Types

ShapeTypeDescription
ShapeType.BentConnector3Two 90-degree bends (most common for flowchart-style diagrams)
ShapeType.BentConnector2One 90-degree bend
ShapeType.BentConnector4Three 90-degree bends
ShapeType.StraightConnector1Direct straight line
ShapeType.CurvedConnector2Single smooth curve
ShapeType.CurvedConnector3Double-bend curve

Top-to-Bottom Connection

Use connection site index 0 (top) for the end shape and index 2 (bottom) for the start shape to create a vertical top-to-bottom connector:

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

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

var top = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 250, 80, 200, 60);
top.AddTextFrame("Decision");

var bottom = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 250, 300, 200, 60);
bottom.AddTextFrame("Action");

var conn = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);
conn.StartShapeConnectedTo = top;
conn.StartShapeConnectionSiteIndex = 2;    // bottom of top box
conn.EndShapeConnectedTo = bottom;
conn.EndShapeConnectionSiteIndex = 0;      // top of bottom box

prs.Save("vertical-connector.pptx", SaveFormat.Pptx);

Flowchart with Multiple Connectors

Create shapes and connectors inline to build a multi-step flowchart on a single slide:

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

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

// Create three labeled boxes
var box1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 260, 60, 160, 50);
box1.AddTextFrame("Start");

var box2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 260, 180, 160, 50);
box2.AddTextFrame("Process Data");

var box3 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 260, 300, 160, 50);
box3.AddTextFrame("End");

// Connect Start → Process (bottom to top)
var conn1 = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);
conn1.StartShapeConnectedTo = box1;
conn1.StartShapeConnectionSiteIndex = 2;   // bottom of Start
conn1.EndShapeConnectedTo = box2;
conn1.EndShapeConnectionSiteIndex = 0;     // top of Process

// Connect Process → End (bottom to top)
var conn2 = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);
conn2.StartShapeConnectedTo = box2;
conn2.StartShapeConnectionSiteIndex = 2;   // bottom of Process
conn2.EndShapeConnectedTo = box3;
conn2.EndShapeConnectionSiteIndex = 0;     // top of End

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

Formatting a Connector

Connectors support the same LineFormat properties as regular shapes, allowing control over line width, dash style, and color:

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

using var prs = new Presentation();
var slide = prs.Slides[0];
var box1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 150, 150, 60);
var box2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 400, 150, 150, 60);

var conn = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);
conn.StartShapeConnectedTo = box1;
conn.StartShapeConnectionSiteIndex = 3;
conn.EndShapeConnectedTo = box2;
conn.EndShapeConnectionSiteIndex = 1;

// Style the connector line
conn.LineFormat.Width = 2.5;
conn.LineFormat.DashStyle = LineDashStyle.Dash;
conn.LineFormat.FillFormat.SolidFillColor.Color = Color.DarkBlue;

prs.Save("styled-connector.pptx", SaveFormat.Pptx);

See Also

 English