Skip to main content
Box

PageCanvas Class

Encapsulates the layout drawing surface.

Namespace: DevExpress.XtraRichEdit.API.Layout

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

NuGet Package: DevExpress.RichEdit.Core

Declaration

public abstract class PageCanvas

The following members return PageCanvas objects:

Remarks

The PageCanvas class provides methods for drawing objects in the document layout.

Use the PagePainter.Canvas property to obtain the PageCanvas object in overridden methods of the PagePainter descendant.

Use the BeforePagePaintEventArgs.Canvas property to access the PageCanvas object and perform a custom draw in the BeforePagePaint event handler.

The PageCanvas enables you to draw lines and shapes, with the specific Draw_GraphicalElement_ method. You can also draw images with the PageCanvas.DrawImage method and text with the PageCanvas.DrawString method.

For complex drawings, you may need to convert the document units of measurement to the units used in layout drawings. The PageCanvas.ConvertToDrawingLayoutUnits method is implemented to accomplish this task.

Example

This code snippet illustrates the implementation of a PagePainter descendant. It draws color rectangles in place of the words and labels a floating picture with a text string drawn over it.

View Example

public class MyLayoutPainter : PagePainter
{
    public override void DrawPlainTextBox(PlainTextBox plainTextBox)
    {
        if (Form1.customDrawText == true)
        {
            Canvas.DrawRectangle(new RichEditPen(Color.FromArgb(141, 179, 226)), plainTextBox.Bounds);
        }
        else base.DrawPlainTextBox(plainTextBox);
    }

    public override void DrawFloatingPicture(LayoutFloatingPicture floatingPicture)
    {
        if (Form1.customDrawImage == true)
        {
            Rectangle bounds = floatingPicture.Bounds;
            Point startPoint = new Point(bounds.X + Canvas.ConvertToDrawingLayoutUnits(10, DocumentLayoutUnit.Pixel), bounds.Y + bounds.Height - Canvas.ConvertToDrawingLayoutUnits(40, DocumentLayoutUnit.Pixel));
            RichEditPen pEn = new RichEditPen(Color.Coral);
            pEn.Thickness = 30;
            pEn.DashStyle = RichEditDashStyle.Dash;
            Canvas.DrawEllipse(pEn, bounds);
            Canvas.DrawString("Approved", new Font("Courier New", 26), new RichEditBrush(Color.DarkMagenta), startPoint);
        }
        else
            base.DrawFloatingPicture(floatingPicture);
    }

    public override void DrawTableCell(LayoutTableCell tableCell)
    {
        if (Form1.customDrawTable == true)
        {
            Rectangle Tbounds = tableCell.Bounds;

            int x = Tbounds.X + Tbounds.Width/2 - Canvas.ConvertToDrawingLayoutUnits(20, DocumentLayoutUnit.Pixel);
            int y = Tbounds.Y + Tbounds.Height/2 - Canvas.ConvertToDrawingLayoutUnits(20, DocumentLayoutUnit.Pixel);
            Rectangle tableRectangle = new Rectangle(x,y, Canvas.ConvertToDrawingLayoutUnits(20, DocumentLayoutUnit.Pixel), 
                Canvas.ConvertToDrawingLayoutUnits(20, DocumentLayoutUnit.Pixel));

            Canvas.FillEllipse(new RichEditBrush(Color.MediumAquamarine), tableRectangle);
            base.DrawTableCell(tableCell);
        }
        else
            base.DrawTableCell(tableCell);
    }

   public override void DrawInlineDrawingObject(InlineDrawingObjectBox inlinePictureBox)
    {
        if (Form1.customDrawPicture == true)
        {
            Rectangle Ebounds = inlinePictureBox.Bounds;
            RichEditPen pen = new RichEditPen(Color.Maroon, 50);
            pen.DashStyle = RichEditDashStyle.Dot;
            Canvas.DrawLine(pen, new Point(Ebounds.X, Ebounds.Y + Ebounds.Height), new Point(Ebounds.X + Ebounds.Width, Ebounds.Y));
            Canvas.DrawLine(pen, new Point(Ebounds.X, Ebounds.Y), new Point(Ebounds.X + Ebounds.Width, Ebounds.Y + Ebounds.Height));
            Rectangle inlineRect = new Rectangle(Ebounds.X, Ebounds.Y, Ebounds.Width, Ebounds.Height);
            Canvas.DrawRectangle(new RichEditPen(Color.Aquamarine, 40), inlineRect);
        }
        else
            base.DrawInlineDrawingObject(inlinePictureBox);
    }

    public override void DrawTextBox(LayoutTextBox textBox)
    {
        if (Form1.customDrawTextBox == true)
        {
            Point[] StarPoints =
                {
            new Point(textBox.Bounds.X+textBox.Bounds.Width/2,textBox.Bounds.Y),
            new Point(textBox.Bounds.X+textBox.Bounds.Width,textBox.Bounds.Y+textBox.Bounds.Height),
            new Point(textBox.Bounds.X,textBox.Bounds.Y+textBox.Bounds.Height/2),
            new Point(textBox.Bounds.X+textBox.Bounds.Width,textBox.Bounds.Y+textBox.Bounds.Height/2),
            new Point(textBox.Bounds.X,textBox.Bounds.Y+textBox.Bounds.Height),
            new Point(textBox.Bounds.X+textBox.Bounds.Width/2,textBox.Bounds.Y)
                };
            Canvas.DrawLines(new RichEditPen(Color.HotPink, 30), StarPoints);
        }
        else
            base.DrawTextBox(textBox);
    }

    public override void DrawNumberingListWithSeparatorBox(NumberingListWithSeparatorBox numberingListWithSeparatorBox)
    {
        if (Form1.customDrawSeparator == true) Canvas.FillRectangle(new RichEditBrush(Color.DarkRed), numberingListWithSeparatorBox.Bounds);
        else base.DrawNumberingListWithSeparatorBox(numberingListWithSeparatorBox);
    }

    public override void DrawPage(LayoutPage page)
    {
        if (Form1.customDrawPage == true)
        {
            Rectangle inlineRect = new Rectangle(100, 100, 150, 200);
            Canvas.DrawRectangle(new RichEditPen(Color.Aquamarine, Canvas.ConvertToDrawingLayoutUnits(4, DocumentLayoutUnit.Pixel)), Canvas.ConvertToDrawingLayoutUnits(inlineRect, DocumentLayoutUnit.Pixel));

        }
        base.DrawPage(page);
    }
}

Inheritance

Object
PageCanvas
See Also