Products Technologies Demo Docs Blog Support Company

Using IFormattedText Objects to Access Elements Across All TextParts in a Document

In TX Text Control, a document consists of separate text areas such as main text, headers, footers and text frames. Each of these areas have their own collections for contained elements such as lines, images, fields or the Selection object. In order to manipulate the text in a HeaderFooter object, you would need to access the HeaderFooter.Selection object. To manipulate text in all headers and footers, you would need to loop through all available objects. To avoid that, we implemented the…

Using IFormattedText Objects to Access Elements Across All TextParts in a Document

In TX Text Control, a document consists of separate text areas such as main text, headers, footers and text frames. Each of these areas have their own collections for contained elements such as lines, images, fields or the TXTextControl.Selection class object.

In order to manipulate the text in a TXTextControl.HeaderFooter class object, you would need to access the TXTextControl.HeaderFooter.Selection property. To manipulate text in all headers and footers, you would need to loop through all available objects.

To avoid that, we implemented the "meta" collection TXTextControl.TextPartCollection class. An instance of this class contains all text parts in a TX Text Control document. Each text part of a document is implemented as an IFormattedText interface. The IFormattedText interface contains properties and methods common to all text parts in a TX Text Control document.

In order to set text to the beginning of each text part in the complete document, the following code can be used:

foreach (IFormattedText ftTextPart in textControl1.TextParts)
{
    ftTextPart.Selection.Start = 0;
    ftTextPart.Selection.Text = "TX Text Control";
}

This method is very handy to access all ApplicationFields in a document:

foreach (IFormattedText ftTextPart in textControl1.TextParts)
{
    foreach (ApplicationField field in ftTextPart.ApplicationFields)
    {
        field.Text = "Test";
    }
}

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.HeaderFooter Class
  • TXTextControl.HeaderFooter.Selection Property
  • TXTextControl.IFormattedText Interface
  • TXTextControl.Selection Class
  • TXTextControl.TextControl.ApplicationFields Property
  • TXTextControl.TextPartCollection Class

Windows Forms

Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.

See Windows Forms products

Related Posts

Windows FormsWPFTutorial

Windows Forms and WPF: End a List on Return when Line is Empty

In the last blog entry, we introduced the TextPartCollection to modify content in all text parts of a document. This sample shows a typical scenario using this meta collection as this list type…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format

Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…


ActiveXASP.NETWindows Forms

Expert Implementation Services for Legacy System Modernization

We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.