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.
DsWord 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.
To add group shape in a document:
C# |
Copy Code |
---|---|
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"); |
To delete group shape in a document:
C# |
Copy Code |
---|---|
//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