Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Getting most out of the InputPositon class

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:Visual Basic .NET
Version:1.0
Released:December 15, 2004
Last modified:January 11, 2008
Requirements:TX Text Control .NET with Visual Basic .NET
Download code:tx_sample_dotnet_nav.zip Download [10.94 KB, ZIP]

Getting most out of the InputPositon class

Click to enlarge

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:

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

  1. Private Sub navigatePage(ByVal page As direction)
  2. Dim newPage As Integer
  3. Select Case page
  4. Case direction.nextPage
  5. newPage = TextControl1.InputPosition.Page + 1
  6. Case direction.previousPage
  7. newPage = TextControl1.InputPosition.Page - 1
  8. Case direction.firstPage
  9. newPage = 1
  10. Case direction.lastPage
  11. newPage = TextControl1.Pages
  12. End Select
  13. If newPage <= TextControl1.Pages Then
  14. TextControl1.InputPosition = New TXTextControl.InputPosition(newPage, 1, 0)
  15. TextControl1.ScrollLocation = New System.Drawing.Point(0, _
  16. TextControl1.InputPosition.Location.Y)
  17. End If
  18. End Sub

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

  1. Public Enum direction
  2. nextPage = 0
  3. previousPage
  4. lastPage
  5. firstPage
  6. 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:

  1. navigatePage(direction.nextPage)

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

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place