.NET, WinForms, XtraRichEdit
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


How to enable line numbering and count the document rows

This example enables line numbering for the first section in the loaded document using the DevExpress.XtraRichEdit.API.Native.Section.LineNumbering property. Line numbering starts at number one and restarts at the new section. Numbers are displayed on each second line and are indented from the text at a distance equal to 75 documents (0.25 of an inch).

Line numberings are allowed to display by setting the AllowDisplayLineNumbers property to true in the DevExpress.XtraRichEdit.SimpleView and DevExpress.XtraRichEdit.DraftView views. To make line numbers visible, the left padding is increased to 60 points.

Font face and color are specified using the Line Number document style.

The Custom Draw technique is used to display the line number column with a color background. To do so, handle the DevExpress.XtraRichEdit.RichEditControl.BeforePagePaint event. Create a custom DevExpress.XtraRichEdit.API.Layout.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 DevExpress.XtraRichEdit.BeforePagePaintEventArgs.Painter property.

To count the lines in the document (document rows), create an instance of the DevExpress.XtraRichEdit.API.Layout.LayoutVisitor descendant and let it traverse the page layout. When it encounters a new row, it calls the VisitRow method. This method increments the row counter to count the lines on a page. To run the visitor each time after building the document layout, handle the DevExpress.XtraRichEdit.API.Layout.DocumentLayout.DocumentFormatted event.