TX Text Control Source Code Library

Getting most out of the InputPositon class

A very common question posed by TX Text Control customers is:

Why are the values from the InputPosition class read-only?

Indeed, the InputPosition class is very useful to get information such as the current page, line column or position of the cursor, but all information is read-only.

The reason for this is simple: A new input position object must be valid, so that it can be used with TX Text Control's InputPosition property. Therefore, it has been implemented as a constructor in the InputPostion class. This guarantees that the new input position is valid.

It can be used in the following form:

public InputPosition(int page, int line, int column);

In this sample application, we are going to show you how to make optimal use of TX Text Control's InputPosition class. We have implemented a simple method which is able to scroll to the next page, the previous page, the first page and the last page of the current document.

Private Sub navigatePage(ByVal page As direction) Dim newPage As Integer Select Case page Case direction.nextPage newPage = TextControl1.InputPosition.Page + 1 Case direction.previousPage newPage = TextControl1.InputPosition.Page - 1 Case direction.firstPage newPage = 1 Case direction.lastPage newPage = TextControl1.Pages End Select If newPage <= TextControl1.Pages Then TextControl1.InputPosition = New TXTextControl.InputPosition(newPage, 1, 0) TextControl1.ScrollLocation = New System.Drawing.Point(0, _ TextControl1.InputPosition.Location.Y) End If End Sub

The navigatePage() method excepts the four parameters of the implemented public enumeration direction:

Public Enum direction nextPage = 0 previousPage lastPage firstPage End Enum

In the method navigatePage(), a new InputPosition object is created with an increased or decreased page number. Once this has been done, the new InputPostion is set.

A call of this method looks like that:

navigatePage(direction.nextPage)

The minimum requirements for this sample application are TX Text Control .NET for Windows Forms trial or TX Text Control .NET for Windows Forms Enterprise retail version and Visual Studio .NET 2003.

 
 

Products

Support

Downloads

Corporate

Buy Now