Skip to main content

How to: Set Background Color for the Line Number Column

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) {
    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;