none
Undo action when deleting shapes in PowerPoint RRS feed

  • Question

  • I have 2 shapes: A and B in a PowerPoint.Slide. I used this tutorial to catch shape events including removing or creating shapes.

    When I got notified about deleting shape A, I will delete shape B at the same time. PowerPoint will understand deleting shape A, and deleting shape B are 2 separate actions. Therefore, after undo, the shape B will be shown, but not the shape A. However, I want the shape A will be shown as well. How can I do that?

    I experiment by deleting shape A, and shape B programmatically at once:

    shapeA.delete(); shapeB.delete();

    and now if I undo, PowerPoint will recover 2 shapes A and B for me. It's what I need.



    • Edited by chipbk11 Monday, October 13, 2014 11:17 AM
    Monday, October 13, 2014 11:01 AM

Answers

  • Hi Chipbk,

    From the description, you want to undelete the Shape B, the Shape A would be recovered too.

    I suggest that you try to add the code in shape create event to complete the another undo action. Here is the code for your reference:

     private void ShapesCreated(MyShapes shapesCreated)
            {
                customTaskPanel.AddMessage("ShapeCreated Event Occurs." + shapesCreated.Count.ToString() + " shape(s) are added to the Sheet.Shapes collection.");
    
                if (shapesCreated.Contains(circleShape.ID))
                {
                    Application.Undo();
                }
            }
    

    But there is some risk for this code. If you delete the Shape B directly rather than through deleting Shape A, the code would make a mistake.

    So, I agree with Rich on group the shapes you want to undo them. That may be a simple way to achieve the goal.

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by chipbk11 Thursday, October 16, 2014 9:55 AM
    Thursday, October 16, 2014 7:41 AM
    Moderator

All replies

  • Place the two shapes in a Group (Home tab, Drawing group, Arrange button). Now when you click one shape, both get selected and if you delete or undo, both are affected.

    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, October 13, 2014 11:11 AM
  • I don't want to group them.
    Monday, October 13, 2014 11:13 AM
  • Hi Chipbk,

    From the description, you want to undelete the Shape B, the Shape A would be recovered too.

    I suggest that you try to add the code in shape create event to complete the another undo action. Here is the code for your reference:

     private void ShapesCreated(MyShapes shapesCreated)
            {
                customTaskPanel.AddMessage("ShapeCreated Event Occurs." + shapesCreated.Count.ToString() + " shape(s) are added to the Sheet.Shapes collection.");
    
                if (shapesCreated.Contains(circleShape.ID))
                {
                    Application.Undo();
                }
            }
    

    But there is some risk for this code. If you delete the Shape B directly rather than through deleting Shape A, the code would make a mistake.

    So, I agree with Rich on group the shapes you want to undo them. That may be a simple way to achieve the goal.

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by chipbk11 Thursday, October 16, 2014 9:55 AM
    Thursday, October 16, 2014 7:41 AM
    Moderator