Accessing Document Sections

All sections are listed in the SectionCollection class that can be accessed using the Sections property.

By inserting a new section using the Add method, a section break character is inserted at the current input position. Using TX Text Control, it is possible to insert a new section that starts at a new page or at a new line. The page size and different headers and footers can only be changed when inserting a new page.

All settings of the previous section are inherited when creating a new document section. In other words, if a specific header is inserted to the previous section, this header will be displayed in the new section as well. To avoid that, the ConnectedToPrevious property of the HeaderFooter object can be set to false. In this case, the new section is getting it's own header.

To modify the headers and footers of a specific section, the HeadersAndFooters property of the specific section must be manipulated. In previous versions of TX Text Control, the headers and footers were accessed through the HeadersAndFooters property of the main control which is no longer recommended. It is still possible, but if more than 1 section is inserted, most of the other collections in the HeaderFooter object are NULL. Example:

The text of each header in every section must be changed. Therefore, all sections and their specific headers and footers must be iterated. The following code snippet shows this approach:

[C#]
foreach (Section sec in textControl1.Sections)
{
    foreach (HeaderFooter hed in sec.HeadersAndFooters)
    {
        hed.Selection.Text = "New Text";
    }
}
[Visual Basic]
For Each sec As TXTextControl.Section In TextControl1.Sections
	For Each hf As TXTextControl.HeaderFooter In sec.HeadersAndFooters
		hf.Selection.Text = "New Text"
	Next
Next

Sections is a layer wrapped over the text and its pages. The text, images, tables and all other elements can be accessed using the normal collections of the main TX Text Control. Only the content in the different headers and footes must be accessed through the specific section.