Document sections allows you to split a document into separate sections to enable different page sizes, margins or headers and footers. Since version 15.0, page columns can be adjusted separately for each inserted section.
When you are not used to word processing, sections might not be self-explanatory. For instance, sections enable users to create documents with mixed page orientation, so that parts are inserted as portrait and other parts as landscape. It is possible to add different headers and footers to specific sections or to include page numbering only for the main part of a document and omit it in an appendix.
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:
foreach (Section sec in textControl1.Sections)
{
foreach (HeaderFooter hed in sec.HeadersAndFooters)
{
hed.Selection.Text = "New Text";
}
}
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.
TX Text Control is shipped with a dialog box that can be used to manipulate the section settings. The first screenshot shows the section format dialog that comes with TX Text Control. It allows users to change the page format for the complete document or the current section.
The following screenshot shows the second tab of the same dialog box. On this tab page, it is possible to specify whether headers and footers are added to the current section, if they should be connected to the previous one and to adjust the different settings for headers and footers.
In the combo boxes, you have three possibilities for headers and footers when applying the changes to the complete document:
When applying the settings to the current section, the following possibilities are available: