Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

ShapeCollection.InsertCanvas(DocumentPosition, SizeF) Method

Inserts a drawing canvas of specified size in the document.

Namespace: DevExpress.XtraRichEdit.API.Native

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

NuGet Package: DevExpress.RichEdit.Core

Declaration

Shape InsertCanvas(
    DocumentPosition pos,
    SizeF size
)

Parameters

Name Type Description
pos DocumentPosition

The position of the canvas anchor.

size SizeF

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

Returns

Type Description
Shape

The canvas embedded in the document.

Remarks

The InsertCanvas method adds a drawing canvas to the page that contains the canvas 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 Shape.CanvasItems property to access the collection of canvas items. The collection’s Add methods allow you to add shapes and pictures to the canvas.

The example below adds a drawing canvas to the document.

Add a canvas to ShapeCollection

Document document = wordProcessor.Document;
// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Insert a drawing canvas.
Shape canvas = document.Shapes.InsertCanvas(document.Range.Start, new SizeF(6f, 1.5f));
// Access the collection of canvas items. 
var canvasItems = canvas.CanvasItems;
// Add a rectangle to the canvas.
var shape1 = canvasItems.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 canvas.
var shape2 = canvasItems.AddPicture(DocumentImageSource.FromFile("Picture_Arrow.png"), new PointF(2.1f, 0.3f));
// Add a parallelogram to the canvas.
var shape3 = canvasItems.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;
See Also