none
Find the content control parent of the selected shape RRS feed

  • Question

  • I have Word document with some shapes (textboxs) inside content controls, when user put the cursor inside a shape, I need to find the content control parent of the selected shape.
    • Edited by Tunisian_BB Thursday, June 20, 2013 4:33 PM
    Thursday, June 20, 2013 4:04 PM

Answers

  • This code is working fine:

    ShapeRange shapeRange = WordApplication.Selection.ShapeRange;
                                if (shapeRange != null)
                                {
                                    Range anchorRange = shapeRange.Anchor;
                                    if (anchorRange != null)
                                        parentCC = anchorRange.ParentContentControl;
                                }
    • Edited by Tunisian_BB Friday, June 21, 2013 7:51 AM formatting
    • Marked as answer by Tunisian_BB Friday, June 21, 2013 10:40 PM
    Friday, June 21, 2013 7:41 AM

All replies

  • This code is working fine:

    ShapeRange shapeRange = WordApplication.Selection.ShapeRange;
                                if (shapeRange != null)
                                {
                                    Range anchorRange = shapeRange.Anchor;
                                    if (anchorRange != null)
                                        parentCC = anchorRange.ParentContentControl;
                                }
    • Edited by Tunisian_BB Friday, June 21, 2013 7:51 AM formatting
    • Marked as answer by Tunisian_BB Friday, June 21, 2013 10:40 PM
    Friday, June 21, 2013 7:41 AM
  • Does that mean your problem is solved?

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, June 21, 2013 10:30 AM
    Moderator
  • Yes  
    • Edited by Tunisian_BB Friday, June 21, 2013 10:44 PM formatting
    Friday, June 21, 2013 10:40 PM