Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I lock shapes in PowerPoint?

I'm working on a Add-in for PowerPoint 2010 (C#) and I want to prevent the end-user to move or edit all the shapes that I have programmatically created.

I have already sought in the framework but I think it's not allowed programmaticaly. Has anyone already encountered this kind of limitations and could help me to find a solution?

I know that some people create their add-in thanks to C++ because there are a lot of limitations in office.

like image 349
monstergold Avatar asked Aug 05 '13 16:08

monstergold


1 Answers

I have found two solutions :

  • The first is to catch all events from the "commandBars.OnUpdate" like this great sample code : http://code.msdn.microsoft.com/CSExcelNewEventForShapes-0e26b1f2#content Then you can impose the position/the color or everything you want to your shape.
  • The second one is more "brutal" > unselect immediately the shape. When you catch all the events from the "CommandBars.OnUpdate" do this :

To see which shape is selected :

var selectedShape = this.Application.ActiveWindow.Selection.ShapeRange[1]

In all my shapes, I have set a tag with an ID. I have just to check that there are an ID in the tags of the selectedShape and if this is the case :

this.Application.ActiveWindow.Selection.Unselect();

Then I show a messageBox to warn the user to do not select this kind of shape. I don't like this solution but it's the only one that I have found and it works.

like image 162
monstergold Avatar answered Oct 03 '22 21:10

monstergold