Displaying line numbers on a page has been an often requested feature. These numbers are not part of the document content. A typical application for this feature is medical transcription where line numbering is required. This can be implemented using TX Text Control with little effort.

Windows Forms

In case of Windows Forms, the line numbers are drawn on top of TXTextControl.TextControl class TX Text Control .NET for Windows Forms
TXTextControl Namespace
TextControl Class
The TextControl class implements a Windows Forms control with high-level text editing features.
using a graphics drawing object. The challenge here is to calculate the position of the line object in client coordinates. In TX Text Control X15, a new method has been introduced to simplify this calculation. The TXTextControl.TextControl.DocumentToClient method TX Text Control .NET for Windows Forms
TXTextControl Namespace
TextControl Class
DocumentToClient Method
Computes coordinates in twips relative to the top-left corner of the document into client coordinates.
converts the coordinates in twips in relation to the top-left corner of the document to client coordinates.

Loading...

The following screenshot shows the rendered line numbers in the left margin area:

Line numbering in Windows Forms

WPF

In WPF, the approach is slightly different and another method has to be used. The TXTextControl.WPF.TextControl.PointToDocument method TX Text Control .NET for WPF
WPF Namespace
TextControl Class
PointToDocument Method
Converts a Point that represents the current coordinate system of the TextControl into a point in document coordinates, which are in twips relative to the top-left corner of the whole document.
has also been introduced in version X15, which converts a document point in the current TextControl coordinate system to client coordinates. This method is used to calculate the correct position of text blocks containing line numbers. The text blocks are then added to a canvas control that is displayed on top of TXTextControl.WPF.TextControl class TX Text Control .NET for WPF
WPF Namespace
TextControl Class
The WPF.TextControl class class implements a control with high-level text editing features.
.

The DocumentToClient() and PointFromDocument() methods are helpful methods and have various applications when client coordinates have to be calculated.

Download the sample for Windows Forms from our GitHub repository:

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Requirements for This Sample

  • Visual Studio 2017 or better
  • TX Text Control .NET for Windows Forms (trial sufficient)


For WPF, you can download the sample here:

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Requirements for This Sample

  • Visual Studio 2017 or better
  • TX Text Control .NET for WPF (trial sufficient)