Adding Animation to PowerPoint Slide Elements in C# | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

Adding Animation to PowerPoint Slide Elements in C#

Syncfusion is happy to share that Essential Presentation (.NET PowerPoint library) has added support to apply and edit animations in a PowerPoint slide from the 2018 Volume 2 (v16.2.0.41) release on. Using animation, you can grab and keep the attention of your audience by emphasizing key points, controlling the focus of the discussion, and entertaining in ways that will make your message memorable. You can animate any individual elements on a slide including text, pictures, and shapes.

Using this animation support in Essential Presentation, you can add a new animation effect or edit an animation effect in an existing PowerPoint slide; and control the direction, trigger, and duration of animation effects. This support is available across all the Microsoft platforms (.NET Framework, .NET Core, UWP, and Xamarin).

Animation effect types

Effects can make an object appear, disappear, or move. They can change an object’s size or color. You can add animation to elements on a slide using the below four types of animation effects:

  • Entrance Effects—An element with an animated entrance is not visible when the slide initially appears. It will appear on the slide in the manner specified by the entrance effect.
  • Emphasis effects—These effects animate the slide element that is already visible on the slide to draw attention to it by changing its appearance.
  • Motion path effects—These effects move an element along a path that you specify, over a period that you specify.
  • Exit effects—These effects allow the elements to leave/disappear from the slide.

Experience the magic of Syncfusion’s C# PowerPoint Library. Witness your ideas come to life with its Microsoft PowerPoint-like editing, conversion, and formatting options.

Applying multiple animation effects to an element

For a slide element, you can apply an animation effect for each animation type (entrance, emphasis, exit, and motion paths). There are 149 animation effects available to apply to a slide element (among them, 50 effects are available for the entrance animation type, 49 effects for the exit animation type, 33 effects for emphasis, and 65 effects for the motion path animation type). Every animation effect will fall within one of these four animation types. Mostly, the animation effects are same for entrance and exit categories. When applying an effect for an exit type alone, you need to specify the type as exit through the PresetClassType property.

For example, the fade animation effect will be available in both entrance and exit categories. The following code example illustrates how to apply a fade animation effect to a rectangle with entrance and exit animation types.

//Create a PowerPoint presentation
using (IPresentation pptxDoc = Presentation.Create())
{

	//Add a blank slide to the presentation.

	ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);

	//Add a shape to the slide.

	IShape shape = slide.Shapes.AddShape(AutoShapeType.Rectangle, 250, 100, 200, 200);

	//Get the sequence of the slide.

	ISequence sequence = slide.Timeline.MainSequence;

	//Add the entrance effect for the shape.

	IEffect entranceEffect = sequence.AddEffect(shape, EffectType.Bounce, EffectSubtype.None, EffectTriggerType.WithPrevious);

	//Add the emphasis effect for the shape.

	IEffect emphasisEffect = sequence.AddEffect(shape, EffectType.GrowShrink, EffectSubtype.None, EffectTriggerType.AfterPrevious);

	//Add the motion effect for the shape.

	IEffect motionEffect = sequence.AddEffect(shape, EffectType.PathLoopdeLoop, EffectSubtype.None, EffectTriggerType.AfterPrevious);

	//Add the exit effect for the shape.

	IEffect exitEffect = sequence.AddEffect(shape, EffectType.RandomBars, EffectSubtype.None, EffectTriggerType.AfterPrevious);

	//Change the presetclass of the effect from default entrance to exit.

	exitEffect.PresetClassType = EffectPresetClassType.Exit;

	//Save the PowerPoint presentation.

	pptxDoc.Save("Sample.pptx");

	//Close the PowerPoint presentation.

	pptxDoc.Close();

}

Learn the capabilities of Syncfusion’s C# PowerPoint Library, where each feature is described by a code example, simplifying the learning curve.

Choose the trigger type

 In PowerPoint presentations, an animation of an element can be triggered by any of the following actions:

  •  On clicking
  • With previous animation
  • After previous animation

The following code example illustrates how to apply a fade animation effect to a rectangle that will appear after a click in the slide show.

//Create a PowerPoint presentation
using (IPresentation presentation = Presentation.Create())
{
	//Add a slide to the presentation.
	ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);

	//Add a shape to appear with entrance category.
	IShape shape = slide.Shapes.AddShape(AutoShapeType.Rectangle, 10, 10, 200, 200);


	//Get the animation sequence.
	ISequence sequence = slide.Timeline.MainSequence;

	//Apply fade to the shape with click trigger. By default, the fade effect will fall in the entrance category. This means the animation will appear with previous animation sequence in parallel.
	IEffect effectClick = sequence.AddEffect(shape, EffectType.Fade, EffectSubtype.None, EffectTriggerType.WithPrevious);

	//Save the PowerPoint presentation.
	presentation.Save("TriggerAnimation.pptx");
}

Apply an animation to text

The Microsoft PowerPoint presentation allows text to be animated in the following ways:

  • Apply animation to the parent shape.
  • Apply individual animation effect options to text in a shape, so that the text will animate separately from its parent shape. This is mostly used with bullets and numbering.

Animate text by apply animation to its parent shape

The following code example illustrates how to apply an animation effect to simple text in a PowerPoint slide.

//Open an existing PowerPoint presentation from file system. 
using (IPresentation pptxDoc = Presentation.Open("Sample.pptx"))
{ 
    //Retrieve the first slide from the presentation. 
    ISlide slide = pptxDoc.Slides[0]; 

    //Retrieve the first shape. 
    IShape shape = slide.Shapes[0] as IShape; 

    //Access the animation sequence to create effects. 
    ISequence sequence = slide.Timeline.MainSequence; 

    //Add swivel effect with vertical subtype to the shape. Build type is used to represent the animated level of the paragraph. 
    IEffect bounceEffect = sequence.AddEffect(shape, EffectType.Swivel, EffectSubtype.Vertical, EffectTriggerType.OnClick); 

    //Save the presentation to the file system. 
    pptxDoc.Save("AnimateSimpleText.pptx"); 
}

Learn to create impactful presentations with Syncfusion’s feature-rich PowerPoint Library. To get started, check out these working demos!

Apply animation effects to bulleted and numbered lists

Animation effects can be applied to each paragraph or list within a shape.  You must set the BuildType enum to apply animation effects for the text. As with Microsoft PowerPoint, you can animate the text up to a maximum of five indentation or list levels. Syncfusion’s Presentation library has the below BuildType enumerator values to control animation for the list levels:

  • ByLevelParagraphs1—Apply the animation effect for the text at indent level 1.
  • ByLevelParagraphs2—Apply the animation effect for the text at indent level 2.
  • ByLevelParagraphs3—Apply the animation effect for the text at indent level 3.
  • ByLevelParagraphs4—Apply the animation effect for the text at indent level 4.
  • ByLevelParagraphs5—Apply the animation effect for the text at indent level 5.

The following code example illustrates how to apply an animation effect to text up to indentation level four in a bulleted list.

//Get the required shape with bulleted/numbered list. 
IShape rectWithBulletdList = slide.Shapes[0] as IShape;

//Get the main sequence of the slide.
ISequence sequence = slide.Timeline.MainSequence;

//Add the Random Effects animation effect to the shape.
IEffect shapeEffect = sequence.AddEffect(rectWithBulletdList, EffectType.RandomEffects, EffectSubtype.None, EffectTriggerType.OnClick, BuildType.ByLevelParagraphs4);

//Iterate the animation effect of the first paragraph.
IEffect firstParaEffect = sequence[1];

//Change the trigger type of the effect to AfterPrevious from default type OnClick.
firstParaEffect.Timing.TriggerType = EffectTriggerType.AfterPrevious;

//Iterate the animation effect of the second paragraph
IEffect secondParaEffect = sequence[2];

//Change the trigger type of the effect to AfterPrevious from default OnClick.
secondParaEffect.Timing.TriggerType = EffectTriggerType.AfterPrevious;

//Iterate the animation effect of the third paragraph.
IEffect thirdParaEffect = sequence[3];

//Change the trigger type of the effect to AfterPrevious from default OnClick.
thirdParaEffect.Timing.TriggerType = EffectTriggerType.AfterPrevious;

//Iterate the animation effect of the fourth paragraph.
IEffect fourthParaEffect = sequence[4];

//Change the trigger type of the effect to AfterPrevious from default OnClick.
fourthParaEffect.Timing.TriggerType = EffectTriggerType.AfterPrevious;
//Change the delay time of the effect to 3 seconds.
fourthParaEffect.Timing.TriggerDelayTime = 3;

//Iterate the animation effect of the fifth paragraph.
IEffect fifthParaEffect = sequence[5];

//Change the trigger type of the effect to AfterPrevious from default OnClick.
fifthParaEffect.Timing.TriggerType = EffectTriggerType.AfterPrevious;

Duration of the animation effect

The speed of the animation effect is determined by the Duration property. This is used to determine how long an animation effect should remain in a slideshow. The following code example illustrates how to control the duration of an animation effect applied to a rectangle in a PowerPoint slide.

//Open an existing presentation from file system. 
using (IPresentation pptxDoc = Presentation.Open("Sample.pptx")) 
{ 
	//Retrieve the first slide from the presentation. 
	ISlide slide = pptxDoc.Slides[0]; 

	//Retrieve a shape from the slide.
	IShape shape = slide.Shapes[0] as IShape; 

	//Access the animation main sequence to modify the effects. 
	ISequence sequence = slide.Timeline.MainSequence; 

	//Get the required animation effect.
	IEffect pathEffect = sequence[0] as IEffect; 

	//Increase the duration of the animation effect in seconds.
	pathEffect.Behaviors[0].Timing.Duration = 5; 

	//Save the presentation to the file system. 
	pptxDoc.Save("Duration.pptx"); 
}

Please refer to the below animation effect created with our Presentation library.

You can find the online sample to create an animation effect like the previous screenshot from here for a quick look—Create PowerPoint animation.

A complete runnable example can be downloaded from here.

Are your presentations lacking that wow-factor? Explore the power of Syncfusion’s C# PowerPoint Library, the ultimate solution for creating dynamic and engaging presentations.

Summary

The PowerPoint library now supports generating PowerPoint files with animation effects and modifying the existing animations applied to the PowerPoint slide elements. Take a moment to investigate the documentation, where you’ll find other options and features, all with accompanying code examples.

If you are new to our PowerPoint library, it is highly recommended that you follow our Getting Started guide.

To learn more about the functionalities of and find code snippets for animation, please refer to our documentation called Working with Animations

If you’re already a Syncfusion user, you can download the product setup here. If you’re not yet a Syncfusion user, you can download a free, 30-day trial on our website.

If you have any questions or require clarification on these features, please let us know in the comments below. You can also contact us through our support forum or Direct-Trac. We are happy to assist you!

If you like this blog post, we think you’ll also like the following free e-books:

C# Succinctly
ASP.NET Core Succinctly
ASP.NET MVC Succinctly
.NET Core Succinctly

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed