How to Set Animations on Shapes in PowerPoint in C#

Animation is a great way to emphasize important points, to control the flow of information, and to increase viewer interest in your presentation. You can animate text, pictures, shapes, tables, SmartArt graphics, and other objects in PowerPoint slide to give them visual effects. This article will focus on how to apply animation effect to a shape using Spire.Presentation in C#.

Step 1: Initialize an instance of Presentation class and get the first slide from the presentation.

Presentation ppt = new Presentation();
ISlide slide = ppt.Slides[0];

Step 2: Insert a rectangle in the slide and fill the shape with purple.

IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 200, 80));
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.Purple;
shape.ShapeStyle.LineColor.Color = Color.White;

Step 3: Apply FadedSwivel animation effect to the shape.

shape.Slide.Timeline.MainSequence.AddEffect(shape, AnimationEffectType.FadedSwivel);

Step 4: Save the file.

ppt.SaveToFile("animations.pptx", FileFormat.Pptx2010);

Output:

How to Set Animations on Shapes in PowerPoint in C#

Full Code:

using Spire.Presentation;
using Spire.Presentation.Drawing.Animation;
using System.Drawing;
using Spire.Presentation.Drawing;

namespace SetAnimationsOnShapes
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ISlide slide = ppt.Slides[0];

            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 200, 80));
            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.Purple;
            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.AppendTextFrame("Animated Shape");
            shape.Slide.Timeline.MainSequence.AddEffect(shape, AnimationEffectType.FadedSwivel);
           
            ppt.SaveToFile("animations.pptx", FileFormat.Pptx2010);
        }
    }
}