Back to Devexpress

ShapeCollection.InsertShape(DocumentPosition, ShapeGeometryPreset, SizeF) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertshape-x28-documentposition-shapegeometrypreset-sizef-x29.md

latest4.0 KB
Original Source

ShapeCollection.InsertShape(DocumentPosition, ShapeGeometryPreset, SizeF) Method

Inserts a shape of specified size in the document.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Shape InsertShape(
    DocumentPosition pos,
    ShapeGeometryPreset preset,
    SizeF size
)
vb
Function InsertShape(
    pos As DocumentPosition,
    preset As ShapeGeometryPreset,
    size As SizeF
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the shape’s anchor.

| | preset | ShapeGeometryPreset |

An enumeration member that defines the shape’s geometry.

| | size | SizeF |

An object that specifies the shape’s width and height. The Document.Unit property defines the measurement units.

|

Returns

TypeDescription
Shape

The shape embedded in the document.

|

Remarks

The InsertShape method adds a shape to the page that contains the shape’s anchor and sets its position as follows:

  • the absolute horizontal position to the right of the column is 0;

  • the absolute vertical position below the paragraph is 0.

Use the following properties to customize shape appearance:

  • Shape.Fill - Allows you to specify shape fill options.

  • Shape.Line - Provides access to format settings for the shape outline.

The example below creates a rectangle and centers it horizontally on the page.

csharp
Document document = wordProcessor.Document;
// Create a rectangle.
Shape rectangle = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, new SizeF(400, 300));
rectangle.HorizontalAlignment = ShapeHorizontalAlignment.Center;
// Fill the rectangle with color.
rectangle.Fill.SetSolidFill(Color.FromArgb(0xFF, 0xEE, 0xAD));
// Format the rectangle border.
ShapeLine border = rectangle.Line;
border.Color = Color.FromArgb(0x4D, 0x64, 0x8D);
border.Thickness = 6;
border.JoinType = LineJoinType.Miter;
vb
Dim document As Document = wordProcessor.Document
' Create a rectangle.
Dim rectangle As Shape = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, New SizeF(400, 300))
rectangle.HorizontalAlignment = ShapeHorizontalAlignment.Center
' Fill the rectangle with color.
rectangle.Fill.SetSolidFill(Color.FromArgb(&HFF, &HEE, &HAD))
' Format the rectangle border.
Dim border As ShapeLine = rectangle.Line
border.Color = Color.FromArgb(&H4D, &H64, &H8D)
border.Thickness = 6
border.JoinType = LineJoinType.Miter

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace