The Page class has been part of TX Text Control's API since version 14.0. In case you either didn't use it or you were not aware of such a class, this post should give you an overview of it and it's benefits.
The Page object represents a formatted page of the current document. Even though a document in TX Text Control is represented by floating text, the Page object is a view of a specific page in the current state.
Prior the introduction of this class, it was quite tricky to select a complete page, to scroll to a specific page or to get the bounding rectangle associated with a page.
The members of the Page class are listed in the following diagram:
|Bounds||Gets the bounding rectangle of the page, in twips, relative to the top of the document.|
|Length||Gets the number of characters of the page, including the page break character at the end of the page.|
|Number||Gets the page's number.|
|NumberInSection||Gets the page number relative to the beginning of the section the page belongs to.|
|Section||Gets the number, one-based, of the section the page belongs to.|
|Start||Gets the number (one-based) of the page's first character.|
|TextBounds||Gets the bounding rectangle of the page's text, in twips, relative to the top of the document.|
|GetImage||Gets an image of the page's contents.|
|Select||Selects the text of the page.|
To get a specific page of the collection, you can use the indexer of the PageCollection. The following code returns the start position (character index) of the second page:
// [C#] int iStartValue = textControl1.GetPages().Start;
Now, how to use this class to scroll to a specific page? The Bounds property of the Page class returns a bounding rectangle of the page relative to the top of the document. This value can be used with the ScrollLocation property. The following code can be used to scroll to the top of page 2:
// [C#] textControl1.ScrollLocation = new Point(textControl1.ScrollLocation.X, textControl1.GetPages().Bounds.Top);
Additionally, the GetImage method can be used to create a bitmap or metafile representation of the current page:
// [C#] Bitmap bmpPage = textControl1.GetPages().GetImage(100, TXTextControl.Page.PageContent.All);
An important notice at the end: The PageCollection is only available, if the TextControl.ViewMode property has been set to PageView.