none
C# Open XML SDK 2.5 - make Shape uneditable, unresizeable and immovable RRS feed

  • Question

  • I have a method AddShape() inside a C# script using the OpenXML SDK 2.5, which adds a Shape to my Presentation. When I open the Presentation in Powerpoint I can move, edit the text and resize the Shape. I want to "lock" the Shape, so that these actions (Moving, Editing the text and resizing) can not be done.

    Are there any ways to achieve this with OpenXML SDK?

    If so which properties do I need to add to the Shape and so forth?

    Thursday, September 3, 2015 8:54 PM

Answers

  • Of course it is possible

    I found a Solution to lock a shape:

    You should append to NonVisualShapeDrawingProperties Drawing.ShapeLocks properties, like in this Example:

    NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties = new NonVisualShapeDrawingProperties() ;
            D.ShapeLocks shapeLocks = new D.ShapeLocks() { NoMove = true, NoResize = true, NoTextEdit = true };
            nonVisualShapeDrawingProperties.Append(shapeLocks);

    Hope it helps!
    Friday, September 4, 2015 8:47 AM

All replies

  • Of course it is possible

    I found a Solution to lock a shape:

    You should append to NonVisualShapeDrawingProperties Drawing.ShapeLocks properties, like in this Example:

    NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties = new NonVisualShapeDrawingProperties() ;
            D.ShapeLocks shapeLocks = new D.ShapeLocks() { NoMove = true, NoResize = true, NoTextEdit = true };
            nonVisualShapeDrawingProperties.Append(shapeLocks);

    Hope it helps!
    Friday, September 4, 2015 8:47 AM
  • Hi asdfman

    Well, I don't know PowerPoint but according to kapri it's possible to lock shapes in a presentation and the COM automation code is provided. That does not help you with Open XML SDK, of course, but knowing it's possible is a start.

    The next step would be for you to create a sample presentation (one slide) with one shape that's locked the way you want. Open the presentation in the Open XML SDK Productivity Tool. Select the element that contains the Shape from the "tree" on the left then click "Reflect code".

    At the right you'll see, on top, the Open XML and below the code required to create the Open XML. This will give you the objects, properties and methods to use in your Open XML SDK code.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, September 4, 2015 2:30 PM
    Moderator