C#/VB.NET 自定義PPT動畫路徑的步驟
更新時間:2021年05月10日 10:33:49 作者:E-iceblue
這篇文章主要介紹了C#/VB.NET 自定義PPT動畫路徑的步驟,幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下
PPT中的動畫效果可分為已有內置動畫以及自定義動畫。設置內置動畫,只需直接指定動畫效果類型即可。本文主要介紹如何實現(xiàn)自定義動畫,即自定義形狀動作線性路徑。附C#及VB.NET代碼供參考。
程序運行環(huán)境如下:
- .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)
{
//創(chuàng)建一個幻燈片文檔(新建的文檔已默認包含一頁幻燈片)
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())
'創(chuàng)建一個幻燈片文檔(新建的文檔已默認包含一頁幻燈片)
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動畫路徑的資料請關注腳本之家其它相關文章!
您可能感興趣的文章:
- C# 多進程打開PPT的示例教程
- C# / VB.NET 在PPT中創(chuàng)建、編輯PPT SmartArt圖形的方法詳解
- C# 實現(xiàn)PPT 每一頁轉成圖片過程解析
- C#將PPT文件轉換成PDF文件
- C#如何添加PPT背景
- C# 實現(xiàn)對PPT文檔加密、解密及重置密碼的操作方法
- C#提取PPT文本和圖片的實現(xiàn)方法
- C# 使用Free Spire.Presentation 實現(xiàn)對PPT插入、編輯、刪除表格
- 在C#里面給PPT文檔添加注釋的實現(xiàn)代碼
- C#向PPT文檔插入圖片以及導出圖片的實例
- C#實現(xiàn)將PPT轉換成HTML的方法
- word ppt excel文檔轉換成pdf的C#實現(xiàn)代碼
相關文章
winform 調用攝像頭掃碼識別二維碼的實現(xiàn)步驟
這篇文章主要介紹了winform 調用攝像頭掃碼識別二維碼的實現(xiàn)步驟,幫助大家更好的理解和學習使用winform,感興趣的朋友可以了解下2021-02-02
C# Ado.net實現(xiàn)讀取SQLServer數(shù)據(jù)庫存儲過程列表及參數(shù)信息示例
這篇文章主要介紹了C# Ado.net實現(xiàn)讀取SQLServer數(shù)據(jù)庫存儲過程列表及參數(shù)信息,結合實例形式總結分析了C#針對SQLServer數(shù)據(jù)庫存儲過程及參數(shù)信息的各種常見操作技巧,需要的朋友可以參考下2019-02-02
小白2分鐘學會Visual Studio如何將引用包打包到NuGet上
這篇文章主要介紹了小白2分鐘學會Visual Studio如何將引用包打包到NuGet上,只需兩步完成打包上傳操作,需要的朋友可以參考下2021-09-09

