Add Exit Animation Effect to a Shape in PowerPoint in C#

In Spire.Presentation, when we add a common animation effect that belongs to both entrance and exit types, it’s applied as entrance effect by default. This article is going to show you how to add exit animation effect to a shape in PowerPoint using Spire.Presentation.

Detail steps:

Step 1: Create a Presentation instance and get the first slide.

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

Step 2: Add a shape to the slide.

IShape starShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 100, 200, 200));

Step 3: Add random bars effect to the shape.

AnimationEffect effect = slide.Timeline.MainSequence.AddEffect(starShape, AnimationEffectType.RandomBars);

Step 4: Change the type of the effect from entrance to exit.

effect.PresetClassType = TimeNodePresetClassType.Exit;

Step 5: Save the file.

ppt.SaveToFile("ExitAnimationEffect.pptx", FileFormat.Pptx2013);

Screenshot:

Add Exit Animation Effect to a Shape in PowerPoint in C#

Full code:

//Create a Presentation instance
Presentation ppt = new Presentation();

//Get the first slide
ISlide slide = ppt.Slides[0];

//Add a shape to the slide
IShape starShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 100, 200, 200));

//Add random bars effect to the shape
AnimationEffect effect = slide.Timeline.MainSequence.AddEffect(starShape, AnimationEffectType.RandomBars);

//Change effect type from entrance to exit
effect.PresetClassType = TimeNodePresetClassType.Exit;

//Save the file
ppt.SaveToFile("ExitAnimationEffect.pptx", FileFormat.Pptx2013);