TX Text Control .NET for Windows Forms

TextPartCollection Class

Class|Introduced in 16.0
Namespace
TXTextControl
Package
TXTextControl.TextControl.WinForms.SDK from the private NuGet feed or Text Control Offline Packages
Assembly
TXTextControl.dll
Install
dotnet add package TXTextControl.TextControl.WinForms.SDK .NET 8 and later. For .NET Framework, reference TXTextControl.dll from the setup.
Implements
ICollection, IEnumerable

Description

An instance of the TextPartCollection class contains all text parts in a TX Text Control document. A text part can either be the document's main text, a text frame, a footnote section or a header or footer. A text frame is represented through a TextFrame object, a header or footer through a HeaderFooter object, a footnote section through a FootnoteSection object and the document's main text is represented through a MainText object. A TextPartCollection object contains all these objects in a geometric order. The first object in the collection is the main text, followed by all text frames in geometric order. At the end of the collection all headers and footers are contained also geometrically ordered. All objects in a text part collection implement the IFormattedText interface. The collection can be obtained with the TextControl.TextParts, WPF.TextControl.TextParts or ServerTextControl.TextParts property. The TextPartCollection class implements the IEnumerable and the ICollection interfaces.

Syntax

public class TextPartCollection : ICollection, IEnumerable

Examples

The following example shows how to loop through all text parts a get the first line of each part.

foreach (object obj in textControl1.TextParts)
{
    Console.WriteLine("First Line: " + ((IFormattedText)obj).Lines[1].Text);
}

The following example works with text parts in the current document. The created object is then available to the surrounding document workflow.

TextPartCollection textPartCollection = textControl.TextParts;
Console.WriteLine("Text Part Collection is ready for use.");

Members

Properties

PropertyDescription
CountGets the number of elements contained in the collection.

Methods

MethodDescription
ActivateSets the input focus to the specified text part. If the activated text part is not in the visible part of the document, the document is scrolled.
CopyToCopies the elements of the collection to an array, starting at a particular index.
GetEnumeratorReturns an enumerator that can be used to iterate through the collection.
GetItemGets a certain text part from the collection.
GetMainTextGets the main text part of the document.

Further Reading

  • Visualize Document Tracked Changes in Web Applications –
  • Using IFormattedText Objects to Access Elements Across All TextParts in a Document –