Back to Devexpress

Line Numbering

windowsforms-9557-controls-and-libraries-rich-text-editor-page-layout-line-numbering.md

latest3.6 KB
Original Source

Line Numbering

  • Jul 10, 2019
  • 2 minutes to read

To switch line numbering on, specify the SectionLineNumbering.CountBy property to any non-zero positive integer value. Other parameters can be set up as illustrated below.

Note

The RichEditView.AllowDisplayLineNumbers property enables you to show or hide line numbers in a view.

The following code snippet enables line numbering for the first section in the loaded document using the 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 in SimpleView and DraftView. To make line numbers visible, the left padding should be increased to 60 points.

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

View Example

csharp
this.richEditControl1.Views.SimpleView.Padding = new DevExpress.Portable.PortablePadding(60, 4, 4, 0);
 this.richEditControl1.Views.DraftView.Padding = new DevExpress.Portable.PortablePadding(60, 4, 4, 0);
 richEditControl1.Views.SimpleView.AllowDisplayLineNumbers = true;
 richEditControl1.Views.DraftView.AllowDisplayLineNumbers = true;

 richEditControl1.Document.Sections[0].LineNumbering.Start = 1;
 richEditControl1.Document.Sections[0].LineNumbering.CountBy = 2;
 richEditControl1.Document.Sections[0].LineNumbering.Distance = 75f;
richEditControl1.Document.Sections[0].LineNumbering.RestartType = DevExpress.XtraRichEdit.API.Native.LineNumberingRestart.Continuous;

 richEditControl1.Document.CharacterStyles["Line Number"].FontName = "Courier";
 richEditControl1.Document.CharacterStyles["Line Number"].FontSize = 10;
 richEditControl1.Document.CharacterStyles["Line Number"].ForeColor = Color.DarkGray;
 richEditControl1.Document.CharacterStyles["Line Number"].Bold = true;
vb
Me.richEditControl1.Views.SimpleView.Padding = New DevExpress.Portable.PortablePadding(60, 4, 4, 0)
 Me.richEditControl1.Views.DraftView.Padding = New DevExpress.Portable.PortablePadding(60, 4, 4, 0)
 richEditControl1.Views.SimpleView.AllowDisplayLineNumbers = True
 richEditControl1.Views.DraftView.AllowDisplayLineNumbers = True

 richEditControl1.Document.Sections(0).LineNumbering.Start = 1
 richEditControl1.Document.Sections(0).LineNumbering.CountBy = 2
 richEditControl1.Document.Sections(0).LineNumbering.Distance = 75F
richEditControl1.Document.Sections(0).LineNumbering.RestartType = DevExpress.XtraRichEdit.API.Native.LineNumberingRestart.Continuous

 richEditControl1.Document.CharacterStyles("Line Number").FontName = "Courier"
 richEditControl1.Document.CharacterStyles("Line Number").FontSize = 10
 richEditControl1.Document.CharacterStyles("Line Number").ForeColor = Color.DarkGray
 richEditControl1.Document.CharacterStyles("Line Number").Bold = True

See Also

How To: Add Line Numbering in the Rich Text Editor