Products Technologies Demo Docs Blog Support Company

How to Remove All Section Breaks in a Document?

TX Text Control 15.0 adds per-section page column support alongside existing section breaks. To remove all section breaks programmatically, iterate through SectionCollection using SectionEnumerator and delete each break by clearing a one-character selection at the break position.

How to Remove All Section Breaks in a Document?

With version 14.0, we introduced document section breaks that allow you to have different page formats in the same document. Version 15.0 implements page columns that can be adjusted section-wise.

Sometimes, it is required to remove all section breaks from a document. This little code snippet shows you how to realize this using the enumerator of the section collection:

private void RemoveAllSections()
{
    TXTextControl.SectionCollection.SectionEnumerator sectionEnum = textControl1.Sections.GetEnumerator();
    int sectionCounter = textControl1.Sections.Count;

    sectionEnum.Reset();
    sectionEnum.MoveNext();
    for (int i = 0; i < sectionCounter; i++)
    {
        TXTextControl.Section curSection = (TXTextControl.Section)sectionEnum.Current;

        if (curSection.Number == 1)
        {
            sectionEnum.MoveNext();
            continue;
        }

        textControl1.Selection.Start = curSection.Start - 2;
        textControl1.Selection.Length = 1;
        textControl1.Selection.Text = "";
    }
 }

As you can see in the loop, it is not required to move to the next current item using the MoveNext() method as we are removing sections dynamically in the same loop.

Feel free to share your comments. I am currently preparing a blog series about the amazing new features of TX Text Control. I will start soon with the ASP.NET DocumentViewer.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsWPF.NET

Create a Table of Contents in Windows Forms using C#

This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.


Windows FormsList.NET

Two Ways to Restart Numbered Lists in TX Text Control

In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…


.NETSample

Paste Special: The Easy Way to Implement

TX Text Control version 15.0 introduced a ClipboardFormat parameter on the Paste method, enabling native Paste Special functionality. The GetClipboardFormats method returns all available clipboard…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

Batch printing multiple documents as a single print job using TX Text Control relies on a .NET PrintDocument with PrintPage and QueryPageSettings events. Each page is rendered individually via the…


.NETSampleTextFields

Removing TextFields in a Loop

Modifying a collection during a standard foreach loop causes runtime errors in .NET. This code snippet shows how to use the TextFieldCollection.TextFieldEnumerator in TX Text Control to safely…

Share on this blog post on: