Back to Devexpress

How to: Create a Shape Group

windowsforms-120676-controls-and-libraries-spreadsheet-examples-shapes-how-to-create-a-shape-group.md

latest1.7 KB
Original Source

How to: Create a Shape Group

  • Apr 22, 2022

The code sample below shows how to combine three shapes into a shape group using the ShapeCollection.GroupShapes method:

csharp
// Create three shapes. 
Worksheet worksheet = spreadsheetControl1.Document.Worksheets[0];
Shape shape1 = worksheet.Shapes.AddShape(ShapeGeometryPreset.RectangularCallout, 100, 100, 300, 300);
Shape shape2 = worksheet.Shapes.AddShape(ShapeGeometryPreset.RegularPentagon, 450, 0, 300, 300);
Shape shape3 = worksheet.Shapes.AddTextBox(300, 500, 200, 200, "Shape Text");

// Combine them into a shape group.
Shape shapeGroup = worksheet.Shapes.GroupShapes(new Shape[] { shape1, shape2, shape3 });
vb
' Create three shapes. 
Dim worksheet As Worksheet = spreadsheetControl1.Document.Worksheets(0)
Dim shape1 As Shape = worksheet.Shapes.AddShape(ShapeGeometryPreset.RectangularCallout, 100, 100, 300, 300)
Dim shape2 As Shape = worksheet.Shapes.AddShape(ShapeGeometryPreset.RegularPentagon, 450, 0, 300, 300)
Dim shape3 As Shape = worksheet.Shapes.AddTextBox(300, 500, 200, 200, "Shape Text")

' Combine them into a shape group.
Dim shapeGroup As Shape = worksheet.Shapes.GroupShapes(New Shape() { shape1, shape2, shape3 })

Tip

Call the ShapeCollection.UngroupShapes method to divide a shape group into single shapes.