Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

I believe this is not possible. A way of achieving this to a certain extent (people can work around it if they figure out how to select the shapes below) is by making a transparent rectangle the size of the canvas and binding a custom event to that (like you described in your comment). The transparent rectangle is overlaying the shapes you created so people can no longer access the shapes that way. Of course if they are capable of figuring out how to select the shapes they can move them anyway...

Alternatively, to make people not do stuff like that (you only stop the inexperienced) you can also set them up as master slides.

Only 'real' solution for people not doing that? Images .. but then they can move the image too!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top