C#/VB.NET 自定义PPT动画路径的步骤

PPT中的动画效果可分为已有内置动画以及自定义动画。设置内置动画,只需直接指定动画效果类型即可。本文主要介绍如何实现自定义动画,即自定义形状动作线性路径。附C#及VB.NET代码供参考。

程序运行环境如下:

  • .Net Framework 4.8
  • Visual Studio
  • Spire.Presentation.dll 6.4.5

所需引用的必要程序集文件如下图:

C#

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

namespace CustomAnimation
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)
            Presentation ppt = new Presentation();
            ISlide slide = ppt.Slides[0];//获取第一页空白幻灯片

            //添加形状(指定形状坐标、大小及相关格式设置)
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 50, 180, 180));
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient;
            shape.Fill.Gradient.GradientStops.Append(0, KnownColors.SkyBlue);
            shape.Fill.Gradient.GradientStops.Append(1, KnownColors.Pink);
            shape.ShapeStyle.LineColor.Color = Color.White;

            //给形状设置动画效果
            AnimationEffect effect = ppt.Slides[0].Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathUser);
            CommonBehaviorCollection common = effect.CommonBehaviorCollection;
            AnimationMotion motion = (AnimationMotion)common[0];
            motion.Origin = AnimationMotionOrigin.Layout;
            motion.PathEditMode = AnimationMotionPathEditMode.Relative;
            MotionPath moinPath = new MotionPath();
            moinPath.Add(MotionCommandPathType.MoveTo, new PointF[] { new PointF(0, 0) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.18f, 0.18f) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(-0.1f, 0.2f) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.25f, 0.2f) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.End, new PointF[] { }, MotionPathPointsType.CurveStraight, true);
            motion.Path = moinPath;

            //保存文档
            ppt.SaveToFile("CustomAnimation.pptx", FileFormat.Pptx2013);
            System.Diagnostics.Process.Start("CustomAnimation.pptx");
        }
    }
}

VB.NET

Imports Spire.Presentation
Imports Spire.Presentation.Collections
Imports Spire.Presentation.Drawing.Animation
Imports System.Drawing

Namespace CustomAnimation
    Class Program
        Private Shared Sub Main(args As String())
            '创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)
            Dim ppt As New Presentation()
            Dim slide As ISlide = ppt.Slides(0)
            '获取第一页空白幻灯片
            '添加形状(指定形状坐标、大小及相关格式设置)
            Dim shape As IAutoShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, New RectangleF(100, 50, 180, 180))
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient
            shape.Fill.Gradient.GradientStops.Append(0, KnownColors.SkyBlue)
            shape.Fill.Gradient.GradientStops.Append(1, KnownColors.Pink)
            shape.ShapeStyle.LineColor.Color = Color.White

            '给形状设置动画效果
            Dim effect As AnimationEffect = ppt.Slides(0).Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathUser)
            Dim common As CommonBehaviorCollection = effect.CommonBehaviorCollection
            Dim motion As AnimationMotion = DirectCast(common(0), AnimationMotion)
            motion.Origin = AnimationMotionOrigin.Layout
            motion.PathEditMode = AnimationMotionPathEditMode.Relative
            Dim moinPath As New MotionPath()
            moinPath.Add(MotionCommandPathType.MoveTo, New PointF() {New PointF(0, 0)}, MotionPathPointsType.CurveAuto, True)
            moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(0.18F, 0.18F)}, MotionPathPointsType.CurveAuto, True)
            moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(-0.1F, 0.2F)}, MotionPathPointsType.CurveAuto, True)
            moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(0.25F, 0.2F)}, MotionPathPointsType.CurveAuto, True)
            moinPath.Add(MotionCommandPathType.[End], New PointF() {}, MotionPathPointsType.CurveStraight, True)
            motion.Path = moinPath

            '保存文档
            ppt.SaveToFile("CustomAnimation.pptx", FileFormat.Pptx2013)
            System.Diagnostics.Process.Start("CustomAnimation.pptx")
        End Sub
    End Class
End Namespace

动画效果:

以上就是C#/VB.NET 自定义PPT动画路径的步骤的详细内容,更多关于C#/VB.NET 自定义PPT动画路径的资料请关注我们其它相关文章!

(0)

相关推荐

  • word ppt excel文档转换成pdf的C#实现代码

    复制代码 代码如下: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms; using Word = Microsoft.Office.Interop.Word;using Excel = Micro

  • C#实现将PPT转换成HTML的方法

    本文是一个C#的小程序,主要实现将ppt转换成html的功能,方法很多,此处与大家分享一下,希望能对大家的项目开发起到一定的借鉴作用. 主要功能代码如下: using System; using System.Collections.Generic; using System.Text; using System.IO; using PPT = Microsoft.Office.Interop.PowerPoint; using System.Reflection; namespace Writ

  • C#向PPT文档插入图片以及导出图片的实例

    PowerPoint演示文稿是我们日常工作中常用的办公软件之一,而图片则是PowerPoint文档的重要组成部分,那么如何向幻灯片插入图片以及导出图片呢?本文我将给大家分享如何使用一个免费版PowerPoint组件-Free Spire.Presentation,以C#/VB.NET编程的方式来快速地实现这两个功能.我们可以从官网下载Free Spire.Presentation,创建项目后添加此DLL作为引用. 插入图片 向PPT文档插入图片时,这里我选择插入两张图片到不同的两张幻灯片中. 具

  • C# 实现对PPT文档加密、解密及重置密码的操作方法

    工作中我们会使用到各种各样的文档,其中,PPT起着不可或缺的作用.一份PPT文档里可能包含重要商业计划.企业运营资料或者公司管理资料等.因此,在竞争环境里,企业重要资料的保密工作就显得尤为重要,而对于重要资料我们可以选择添加密码的形式来进行文档保护.本文将介绍如何通过C#来给PPT添加密码,当然你也可以根据需要来修改密码或者解除密码.下面将对三种操作方法进行具体讲述. 所用工具: Spire.Presentation for. NET Visual Studio 2013 工具使用说明:Spir

  • C# 实现PPT 每一页转成图片过程解析

    要实现PPT转图片,首先需要引用两个DLL. 我这里用的这个这个版本 Microsoft.Office.Interop.PowerPoint 12.0 Microsoft Office 12.0 object Library 如下图: 代码如下: private void pptToImg(string pptPath, string imgPath) { var app = new Microsoft.Office.Interop.PowerPoint.Application(); var p

  • C# 使用Free Spire.Presentation 实现对PPT插入、编辑、删除表格

    现代学习和办公当中,经常会接触到对表格的运用,像各种单据.报表.账户等等.在PPT演示文稿中同样不可避免的应用到各种数据表格.对于在PPT中插入表格,我发现了一个新方法,不过我用到了一款免费的.NET组件--Free Spire.Presentation,在C#中添加该产品DLL文件,可以简单快速地实现对演示文稿的表格插入.编辑和删除等操作.有需要的话可以在下面的网址下载:https://www.e-iceblue.cn/Downloads/Free-Spire-Presentation-NET

  • C# 多进程打开PPT的示例教程

    1.背景 PPT文件打开和操作是在一个进程中进行的,如果对多个PPT进行操作,PowerPoint进程默认会以阻塞的方式依次进行,如果打开的PPT特别大(比如超过1GB)很容易造成PPT无响应,这样几乎所有的PPT操作都无法进行. 解决PPT无响应的一种方式是定时检测PPT进程(POWERPNT.exe)是否无响应,如果无响应就将POWERPNT.exe进程Kill掉,重新打开PPT.这种方式并不能解决需要多个PPT操作的问题,如果多个PPT文件都很大,操作多个PPT会频繁出现PPT无响应的情况

  • C#如何添加PPT背景

    我们在创建Powerpoint文档时,系统默认的幻灯片是空白背景的,很多时候我们需要自定义幻灯片背景,以达到美观的文档效果.在下面的示例中将介绍给PowerPoint幻灯片设置背景的方法,主要包含以下三个部分: 添加纯色背景 添加渐变色背景 添加图片作为背景 所需工具 Free Spire.Presentation for .NET 版本3.3 (社区版) 示例代码(供参考) 步骤 1 :添加如下using指令 using Spire.Presentation; using Spire.Pres

  • C#将PPT文件转换成PDF文件

    这里在提供C#代码,将PPT转成PDF.直接上代码: 要引入Microsoft.Office.Interop.PowerPoint; 版本12.0.0.0: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Runtime.InteropServices; using Microsoft.Office.Interop

  • 在C#里面给PPT文档添加注释的实现代码

    平常开会或者做总结报告的时候我们通常都会用到PowerPoint演示文稿,我们可以在单个幻灯片或者全部幻灯片里面添加注释,这样观众可以从注释内容里面获取更多的相关信息. 有些朋友不清楚如何在幻灯片里面添加注释,下面我跟大家分享一下如何在C#里面为幻灯片添加注释. 在这里我使用了一个免费控件--Free Spire.Presentation,有兴趣的朋友可以下载使用. 需要添加的命名空间: using Spire.Presentation; using System.Drawing; 详细步骤和代

  • C#提取PPT文本和图片的实现方法

    在图文混排的文档中,我们可以根据需要将文档中的文字信息或者图片提取出来,通过C#代码可以提取Word和PDF文件中的文本和图片,那么同样的,我们也可以提取PPT幻灯片当中的文本和图片.本篇文档将讲述如何使用C#来实现提取PPT文本和图片的操作.首先也是需要安装组件Spire.Presentation,然后添加引用dll文件到项目中.下面是主要的代码步骤. 原文档: 1. 提取文本 步骤一:创建一个Presentation实例并加载文档 Presentation presentation = ne

  • C# / VB.NET 在PPT中创建、编辑PPT SmartArt图形的方法详解

    本文介绍通过C#和VB.NET程序代码来创建和编辑PPT文档中的SmartArt图形.文中将分两个操作示例来演示创建和编辑结果. 使用工具:Spire.Presentation for .NET hotfix 5.9.5 Dll文件引用: 方式1:下载包.下载后,解压,打开Bin文件夹,根据自己用的.NET Framework选择相应的文件夹,如:此示例中使用的是NET4.0,即打开NET4.0文件,找到Spire.Presentation.dll文件.找到dll文件后,在vs程序中添加引用该d

随机推荐