RichEditDocumentServer.BeforePagePaint Event
Enables you to specify a custom PagePainter descendant to alter the way the layout elements are drawn.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.RichEdit.v18.2.Core.dll
Declaration
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-enable-line-numbering-and-count-the-document-rows-t531470
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;
}