Back to Devexpress

ShapeCollection.InsertGroup(DocumentPosition) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertgroup-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md

latest4.4 KB
Original Source

ShapeCollection.InsertGroup(DocumentPosition) Method

Inserts a shape group in the document.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Shape InsertGroup(
    DocumentPosition pos
)
vb
Function InsertGroup(
    pos As DocumentPosition
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the group’s anchor.

|

Returns

TypeDescription
Shape

The group embedded in the document.

|

Remarks

The InsertGroup method positions a shape group at the top-left corner of the page that contains the group’s anchor.

Use the Add methods of the Shape.GroupItems collection to add nested groups, shapes, and pictures to an existing group.

The example below creates a shape group in the document.

csharp
Document document = wordProcessor.Document;
// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Insert a shape group.
Shape group = document.Shapes.InsertGroup(document.Range.Start);
// Specify the group position relative to the left and top edges of the page. 
group.Offset = new PointF(1.5f, 1f);
// Access the collection of group items. 
var groupItems = group.GroupItems;
// Add a rectangle to the group.
var shape1 = groupItems.AddShape(ShapeGeometryPreset.Rectangle, new RectangleF(0f, 0f, 2f, 1.5f));
shape1.Fill.SetSolidFill(Color.FromArgb(0xA4, 0xFF, 0xFF));
shape1.Line.Color = Color.DarkGray;
shape1.Line.Thickness = 2;
// Add a picture to the group.
var shape2 = groupItems.AddPicture(DocumentImageSource.FromFile("Picture_Arrow.png"), new PointF(2.1f, 0.3f));
// Add a parallelogram to the group.
var shape3 = groupItems.AddShape(ShapeGeometryPreset.Parallelogram, new RectangleF(3.8f, 0f, 2f, 1.5f));
shape3.Fill.SetSolidFill(Color.FromArgb(0xFF, 0xA5, 0xA5));
shape3.Line.Color = Color.DarkGray;
shape3.Line.Thickness = 2;
vb
Dim document As Document = wordProcessor.Document
' Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Insert a shape group.
Dim group As Shape = document.Shapes.InsertGroup(document.Range.Start)
' Specify the group position relative to the left and top edges of the page. 
group.Offset = New PointF(1.5F, 1F)
' Access the collection of group items. 
Dim groupItems As GroupShapeCollection = group.GroupItems
' Add a rectangle to the group.
Dim shape1 As NestedShape = groupItems.AddShape(ShapeGeometryPreset.Rectangle, New RectangleF(0F, 0F, 2F, 1.5F))
shape1.Fill.SetSolidFill(Color.FromArgb(&HA4, &HFF, &HFF))
shape1.Line.Color = Color.DarkGray
shape1.Line.Thickness = 2
' Add a picture to the group.
Dim shape2 As NestedShape = groupItems.AddPicture(DocumentImageSource.FromFile("Picture_Arrow.png"), New PointF(2.1F, 0.3F))
' Add a parallelogram to the group.
Dim shape3 As NestedShape = groupItems.AddShape(ShapeGeometryPreset.Parallelogram, New RectangleF(3.8F, 0F, 2F, 1.5F))
shape3.Fill.SetSolidFill(Color.FromArgb(&HFF, &HA5, &HA5))
shape3.Line.Color = Color.DarkGray
shape3.Line.Thickness = 2

Use the GroupShapeCollection.Ungroup method to split the shape group into individual drawing objects.

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace