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 =…

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.
Related Posts
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.
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…
Paste Special: The Easy Way to Implement
In an older sample, I showed how to implement a paste special functionality by accessing the clipboard directly using .NET functionality. In version 15.0, we implemented this functionality…
Batch Printing: How to Print Documents in One Print Job
A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our…
Removing TextFields in a Loop
A typical problem with collections is the fact that you can't remove elements of the collection in a loop. To remove specific fields in TX Text Control, you could add the fields to another array…