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

Getting the text of a specific page without the Selection class

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C# .NET
Version:1.0
Released:April 24, 2007
Last modified:January 11, 2008
Requirements:TX Text Control .NET with C# .NET
Download code:tx_getpagetext.zip Download [12.71 KB, ZIP]
Click to enlarge

Generally, the powerful Selection class can be used to retrieve text or manipulate parts of a document.

Sometimes, however, it is necessary to retrieve the text at a specific position, without previously selecting it - this avoids flickering and cursor displacement.

TX Text Control offers sophisticated classes in order to get the character index position from a specific location. This can be used to retrieve the string at the current mouse position or similar tasks.

In this sample, we are going to calculate the page bounds using the page size, the gap between the pages in the PageView ViewMode and the page margins.

The diagram above illustrates how to calculate the start position and the end position of the current page. Using the TextChar.GetItem() method and the calculated location, it is possible to retrieve the character index positions of these points.

  1. int startValue = textControl1.TextChars.GetItem(new Point(xValue, yValue), true).Number;

These indexes are used with the .NET String.SubString() method with the complete text of the TextControl instance to get the partial text between these two locations.

  1. string PageText = textControl1.Text.Replace("\r\n", "\n").Substring _
  2. (startValue - 1, endValue - (startValue - 1));

The minimum requirements for this sample application are TX Text Control .NET 13.0 trial version and Visual Studio 2005.

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