Skip to main content
All docs
V25.1
  • CanvasShapeCollection.Clear() Method

    Removes all shapes from the canvas.

    Namespace: DevExpress.XtraRichEdit.API.Native

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

    NuGet Package: DevExpress.RichEdit.Core

    Declaration

    void Clear()

    Remarks

    Use the Clear method to delete all drawing objects from a canvas. Call the ShapeCollection.Remove or ShapeCollection.RemoveAt method to remove the canvas from the document.

    The following example removes all objects from a drawing canvas:

    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);
    // Specify the canvas height.
    canvas.Height = 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;
    // Clear the canvas.
    canvasItems.Clear();
    // Remove the canvas from the document.
    // document.Shapes.Remove(canvas);
    
    See Also