Reorder overlapping shapes in presentation

2014-07-31 09:12:04 Written by  support iceblue
Rate this item
(0 votes)

As is shown in the following presentation slide, shapes automatically stack in separate layers as you add them. To change the order of overlapping shapes, we can move the layers forward and backward. But how can we achieve this task programmatically using C# or VB.NET? This article is aimed to present you a solution on how to reorder overlapping shapes using Spire.Presentation.

Reorder overlapping shapes in presentation

In the early edition, Spire.Presentation is already capable of adding different kinds of shapes to the slides, setting color and fill style of the shape. In the Version2.0.18, we add reordering overlapping shapes as a new feature to satisfy our customer’s demands. Now, let’s see how to make it happen with sample code snippet.

Step 1: Create a new instance of Spire.Presentation class and load the test file.

Spire.Presentation.Presentation presentation = new Presentation();
presentation.LoadFromFile("..\\..\\test.pptx");

Step 2: Get the first shape from the slide.

IShape shape = presentation.Slides[0].Shapes[0];

Step 3: Change the shape's Zorder by setting its position index.

presentation.Slides[0].Shapes.ZOrder(1, shape);

Step 4: Save to a PPTX file and launch the file.

string output = "output.pptx";
presentation.SaveToFile(output,FileFormat.Pptx2010);
System.Diagnostics.Process.Start(output);

Output:

Reorder overlapping shapes in presentation

Full code:

[C#]
using Spire.Presentation;

namespace ReorderOverlappingShape
{

    class Program
    {

        static void Main(string[] args)
        {
            //Create an instance of Spire.Presentation
            Spire.Presentation.Presentation presentation = new Presentation();
            //Load a pptx file
            presentation.LoadFromFile("..\\..\\test.pptx");

            //Get the first shape of the first slide
            IShape shape = presentation.Slides[0].Shapes[0];
            //Change the shape's zorder
            presentation.Slides[0].Shapes.ZOrder(1, shape);

            //Save to a pptx2010 file.
            string output = "output.pptx";
            presentation.SaveToFile(output, FileFormat.Pptx2010);
            //Launch the output file
            System.Diagnostics.Process.Start(output);

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

Namespace ReorderOverlappingShape

	Class Program

		Private Shared Sub Main(args As String())
			'Create an instance of Spire.Presentation
			Dim presentation As Spire.Presentation.Presentation = New Presentation()
			'Load a pptx file
			presentation.LoadFromFile("..\..\test.pptx")

			'Get the first shape of the first slide
			Dim shape As IShape = presentation.Slides(0).Shapes(0)
			'Change the shape's zorder
			presentation.Slides(0).Shapes.ZOrder(1, shape)

			'Save to a pptx2010 file.
			Dim output As String = "output.pptx"
			presentation.SaveToFile(output, FileFormat.Pptx2010)
			'Launch the output file
			System.Diagnostics.Process.Start(output)

		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title: Reorder overlapping shapes
Last modified on Friday, 24 September 2021 09:20