Skip to main content
A newer version of this page is available. .

RichEditControl.BeforePagePaint Event

Enables you to specify a custom PagePainter descendant to alter the way the layout elements are drawn.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v20.2.dll

NuGet Package: DevExpress.Win.RichEdit

Declaration

public event BeforePagePaintEventHandler BeforePagePaint

Event Data

The BeforePagePaint event's data class is BeforePagePaintEventArgs. The following properties provide information specific to this event:

Property Description
Canvas Provides access to layout drawing surface.
CanvasOwnerType Determines the type of device to which the document layout is rendered.
Page Provides access to the current page being rendered.
Painter Gets or sets the painter object which implements methods for drawing layout elements.

Example

This code sample illustrates how to handle the RichEditControl.BeforePagePaint event to draw a color rectangle on the page canvas. The drawn rectangle is the line number column background.

To perform a custom draw, create a custom PagePainter descendant which implements the methods required to draw the column background and the line numbers themselves. Specify an instance of the custom painter using the BeforePagePaintEventArgs.Painter property. To check whether the page is rendered for printing, use the BeforePagePaintEventArgs.CanvasOwnerType property.

The MyPagePainter class uses the Line Number document style to draw line numbers. This is done to make them look like the line numbers drawn in the usual way as described in the Line Numbering topic.

View Example

private void RichEditControl1_BeforePagePaint(object sender, DevExpress.XtraRichEdit.BeforePagePaintEventArgs e) {
    if (e.CanvasOwnerType == DevExpress.XtraRichEdit.API.Layout.CanvasOwnerType.Printer) {
        return;
    }
    DevExpress.XtraRichEdit.API.Native.CharacterStyle style = richEditControl1.Document.CharacterStyles["Line Number"];
    MyPagePainter customPagePainter = new MyPagePainter(richEditControl1, SystemColors.Info, style);
    customPagePainter.LineNumberPadding = 60;
    e.Painter = customPagePainter;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeforePagePaint event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also