How to add line arrow to presentation slides in C#

2015-06-09 09:15:16 Written by  support iceblue
Rate this item
(0 votes)

We have introduced how to add shapes to the slides by Spire.Presentaion. Spire.Presentation supports to work with lots of shapes, such as triangle, rectangle, ellipse, star, line and so on. This time we will show you how to add line arrow to the slides in C#.

Here comes to the code snippet.

Step 1: Create a PPT document.

Presentation presentation = new Presentation();

Step 2: Add a line to the slides and set its color to red.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Line, new RectangleF(50, 100, 100, 100));
shape.ShapeStyle.LineColor.Color = Color.Red;

Step 3: Set the line arrow by using LineEndType.

shape.Line.LineEndType = LineEndType.StealthArrow;

Step 4: Save and launch to view the PPTX document.

presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("shape.pptx");

Effective screenshots:

How to add line arrow to presentation slides in C#

Full codes:

using Spire.Presentation;
using System.Drawing;

namespace AddLineArrow
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Line, new RectangleF(50, 100, 100, 100));
            shape.ShapeStyle.LineColor.Color = Color.Red;
            shape.Line.LineEndType = LineEndType.StealthArrow;

            shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Line, new RectangleF(300, 250, 150, 150));
            shape.Rotation = -45;
            shape.Line.LineEndType = LineEndType.TriangleArrowHead;

            presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("shape.pptx");


        }
    }
}

Additional Info

  • tutorial_title: Add line arrow to presentation slides in C#
Last modified on Friday, 24 September 2021 09:20