Working with Connectors — Aspose.Slides FOSS for .NET

Connectors are shapes that visually link two other shapes with a line. Aspose.Slides FOSS for .NET supports bent, straight, and curved connectors. 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

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

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

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

static IAutoShape AddBox(ISlide slide, string text, float x, float y,
    float w = 160, float h = 50)
{
    var s = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, y, w, h);
    s.AddTextFrame(text);
    return s;
}

static IConnector Connect(ISlide slide, IShape s1, int site1, IShape s2, int site2)
{
    var conn = slide.Shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);
    conn.StartShapeConnectedTo = s1;
    conn.StartShapeConnectionSiteIndex = site1;
    conn.EndShapeConnectedTo = s2;
    conn.EndShapeConnectionSiteIndex = site2;
    return conn;
}

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

var start = AddBox(slide, "Start", 260, 60);
var process = AddBox(slide, "Process Data", 260, 180);
var end = AddBox(slide, "End", 260, 300);

Connect(slide, start, 2, process, 0);    // start -> process (bottom to top)
Connect(slide, process, 2, end, 0);      // process -> end (bottom to top)

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

Formatting a Connector

Connectors support the same LineFormat properties as other shapes:

using Aspose.Slides.Foss;
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 = System.Drawing.Color.DarkBlue;

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

See Also