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 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 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 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 .

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)