可以将形状分组,以便它们作为一个单元来工作。如果你经常使用它们,组合形状很有用。本文将介绍如何在PowerPoint幻灯片中创建组合形状。
C#
//创建PowerPoint文档
Presentation ppt = new Presentation();
//获取第一张幻灯片
ISlide slide= ppt.Slides[0];
//添加一个矩形
IShape rectangle = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(20, 100, 200, 40));
rectangle.Fill.FillType = FillFormatType.Solid;
rectangle.Fill.SolidColor.KnownColor = KnownColors.Gold;
rectangle.Line.Width = 0.1f;
//添加一个带状形状
IShape ribbon = slide.Shapes.AppendShape(ShapeType.Ribbon2, new RectangleF(60, 75, 120, 80));
ribbon.Fill.FillType = FillFormatType.Solid;
ribbon.Fill.SolidColor.KnownColor = KnownColors.Purple;
ribbon.Line.Width = 0.1f;
//将两个形状添加到ArrayList数组
ArrayList list = new ArrayList();
list.Add(rectangle);
list.Add(ribbon);
//组合数组中的形状
ppt.Slides[0].GroupShapes(list);
//保存文档
ppt.SaveToFile("output.pptx", FileFormat.Pptx2010);
VB.NET
'创建PowerPoint文档
Dim ppt As New Presentation()
'获取第一张幻灯片
Dim slide As ISlide = ppt.Slides(0)
'添加一个矩形
Dim rectangle As IShape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(20, 100, 200, 40))
rectangle.Fill.FillType = FillFormatType.Solid
rectangle.Fill.SolidColor.KnownColor = KnownColors.Gold
rectangle.Line.Width = 0.1F
'添加一个带状形状
Dim ribbon As IShape = slide.Shapes.AppendShape(ShapeType.Ribbon2, New RectangleF(60, 75, 120, 80))
ribbon.Fill.FillType = FillFormatType.Solid
ribbon.Fill.SolidColor.KnownColor = KnownColors.Purple
ribbon.Line.Width = 0.1F
'将两个形状添加到ArrayList数组
Dim list As New ArrayList()
list.Add(rectangle)
list.Add(ribbon)
'组合数组中的形状
ppt.Slides(0).GroupShapes(list)
'保存文档
ppt.SaveToFile("output.pptx", FileFormat.Pptx2010)