Rotate Shapes on PowerPoint Slide with .NET

2014-08-08 03:32:46 Written by  support iceblue
Rate this item
(0 votes)

Various kinds of shapes like triangle, rectangle, ellipse, star, line and etc, can be created with Spire.Presentation. To make shapes more compatible with the entire slide, not only can we set color and choose fill style of the shape, we can also rotate shapes to a desired degree. This article is aimed to provide a simple example.

To begin with, create or open a .NET class application in Visual Studio 2005 or above versions, add Spire.Presentation.dll to your .NET project assemblies. Then, you are able create and format shapes using the sample C# code we have offered below.

Code snippets for rotate shapes on slide:

Step 1: Create an instance of Presentation class.

Presentation presentation = new Presentation();

Step 2: Add a new shape - Triangle ,to PPT slide.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Triangle, new RectangleF(100, 100, 100, 100));

Step 3: Rotate the shape to 180 degree.

shape.Rotation = 180;  

Step 4: Set the color and fill style of shape.

shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.BlueViolet;
shape.ShapeStyle.LineColor.Color = Color.Black;

Step 5: Save and launch the file.

presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("shape.pptx");

Effect Screenshot:

Rotate Shapes on PowerPoint Slide with .NET

Full code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace RotateShape
{

    class Program
    {

        static void Main(string[] args)
        {
           //create PPT document 
            Presentation presentation = new Presentation();

            //append new shape - Triangle
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Triangle, new RectangleF(100, 100, 100, 100));                     
            //set rotation to 180
            shape.Rotation = 180;  

            //set the color and fill style of shape
            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.BlueViolet;
            shape.ShapeStyle.LineColor.Color = Color.Black;

            //save the document
            presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("shape.pptx");
        }

        }
    }
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing

Namespace RotateShape

	Class Program

		Private Shared Sub Main(args As String())
			'create PPT document 
			Dim presentation As New Presentation()

			'append new shape - Triangle
			Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Triangle, New RectangleF(100, 100, 100, 100))
			'set rotation to 180
			shape.Rotation = 180

			'set the color and fill style of shape
			shape.Fill.FillType = FillFormatType.Solid
			shape.Fill.SolidColor.Color = Color.BlueViolet
			shape.ShapeStyle.LineColor.Color = Color.Black

			'save the document
			presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("shape.pptx")
		End Sub

	End Class
End Namespace

Additional Info

  • tutorial_title: Rotate Shapes on PowerPoint Slide
Last modified on Friday, 24 September 2021 09:20