[]
        
(Showing Draft Content)

Group Shape

Group shape is a shape element which can be used to add multiple shapes which need to be grouped together. It provides unified properties for child shapes and can be regarded as a shape container.

GcWord allows you to add a group shape and add multiple shapes to it. A group shape can be added by using Add and Insert methods of GroupShapeCollection class. You can also access the previous or next group shapes, apply fill format or group fill properties and ungroup the grouped shapes by using methods provided by GroupShape class.

Note: Deleting a group shape deletes all the shapes inside it.

Add Group Shape

To add group shape in a document:

  1. Create a new Word document by instantiating GcWordDocument class.

  2. Add a run to a newly added paragraph by using Add method of RunCollection class.

  3. Add a group shape by using Add method of GroupShapeCollection class.

  4. Add two shapes inside group shape by using Add method of ShapeCollection class.

  5. Move the horizontal and vertical position of second shape by using Offset property of ShapeHorizontalPosition class so that it does not overlap the first shape.

    var doc = new GcWordDocument();
    
    //Add run element          
    var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
    
    //Create group shape with initial width 500 and height 500
    var group_shape = run.GetRange().GroupShapes.Add(500, 500);
    
    //Create two shapes inside group shape
    var firstShape = group_shape.GetRange().Shapes.Add(202, 250, "First shape");
    var secondshape = group_shape.GetRange().Shapes.Add(300, 400, "Second shape");
    
    //Move second shape 100 points right and 100 points lower
    secondshape.Position.Horizontal.Offset = 100;
    secondshape.Position.Vertical.Offset = 100;
    
    //Save document
    doc.Save("GroupShape.docx");

Delete Group Shape

To delete group shape in a document:

  1. Load the document containing group shape using Load method of GcWordDocument class.

  2. Delete the group shape by using Delete method of ContentObject class.

    //Load document
    doc.Load("GroupShape.docx");
    
    //Access first group shape
    GroupShape gs = doc.Body.GroupShapes.First;
    //Delete group shape
    gs.Delete();
    
    doc.Save("GroupDelete.docx");

Limitations

  • Unsupported Properties: NonVisualGroupDrawingShapePropsExtensionList, GroupShapeLocks, OfficeArtExtensionList, Scene3DType, ShapePropertiesExtensionList

  • Unsupported Effects and derived classes: EffectsDAG and EffectsList