Products Technologies Demo Docs Blog Support Company

Find and Highlight Strings in All Text Parts

A document consists of different text parts: The main text, headers, footers and text frames. The TextPartCollection is a meta collection that allows the iteration of document elements in all document parts. The IFormattedText interface provides properties and methods common to all text parts in a TX Text Control document. Additionally, an object of type IFormattedText has a separate Find method. In order to find and highlight a specific string in all text parts, the following easy code…

Find and Highlight Strings in All Text Parts

A document consists of different text parts: The main text, headers, footers and text frames. The TextPartCollection is a meta collection that allows the iteration of document elements in all document parts. The IFormattedText interface provides properties and methods common to all text parts in a TX Text Control document.

Additionally, an object of type IFormattedText has a separate Find method. In order to find and highlight a specific string in all text parts, the following easy code snippet can be used:

public void HighlightAll(string Text)
{
    foreach (TXTextControl.IFormattedText obj in textControl1.TextParts)
    {
        int index = -1;

        do
        {
            index = obj.Find(Text, index + 1,
                TXTextControl.FindOptions.NoMessageBox);

            obj.Selection.TextBackColor = Color.Red;
        } while (index != -1);
    }
}

As a result, all instances of a specific string ("TEST") are highlighted in red:

Find and highlight strings in all text parts

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsGetting StartedTutorial

Windows Forms Tutorial: Create Your First Windows Forms C# Application

This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.


ASP.NETASP.NET CoreMailMerge

How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#

Mail merge is the process of merging data, such as Json or IEnumerable objects, into a template document, such as a DOC or DOCX file. This tutorial is a walkthrough of the steps necessary to…


AngularDocument EditorNode.js

Creating an Angular Document Editor Application with a Node.js WebSocket Server

This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.


ASP.NETASP.NET CoreMailMerge

Adding SVG Watermarks to Documents

This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.


ASP.NETASP.NET CoreMailMerge

Using MailMerge in ASP.NET Core 6 Web Applications

This article shows how to use the TX Text Control ASP.NET MailMerge class to merge templates with JSON data within a .NET 6 application in Visual Studio 2022.