# Sections and Page Layout

> Insert section breaks, set landscape pages, margins and columns in a Windows Forms TextControl with SectionCollection, SectionFormat and the Page Setup dialog.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Editor > Sections and Page Layout
- **2847 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/sections/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/sections/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/sections/llms-full.txt

---

Page size, margins, orientation and page columns belong to a section, and one document can have several: a portrait report with a landscape page for a wide table, a title above two columns of text, an appendix with other margins. Users of a Windows Forms `TextControl` set them on the **Page Layout** tab and in the **Page Setup** dialog box and insert section breaks from the ribbon; your code does the same through `Sections` and the page properties of the control.

The methods below go into *Form1.cs* of the application from [Create Your First Windows Forms Application](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-editor/first-application/llms-full.txt) and are called from the `Click` handler of a button. Headers and footers, which also belong to sections, are described in [Headers and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/headers-footers/llms-full.txt), and sections in code without a user interface in [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/sections-headers/llms-full.txt).

### What a Section Is

A [Section](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/section/llms-full.txt) is a part of the document with its own page size, margins, orientation, page columns, page border and headers and footers. Every document has at least one section, and sections are numbered from 1.

![Class diagram of the section and page classes: TextControl, WPF.TextControl and ServerTextControl with Sections, PageSize, PageMargins, PageUnit and SectionFormatDialog, SectionCollection, Section, SectionFormat, PageBorder, PageSize, PageMargins and the Page classes.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/sections-class-diagram.4b456f42.webp)

- **A layer over the text.** The text, tables and images of a section are in the usual collections of the `TextControl`; only headers and footers are reached through the section.
- **Inherited settings.** A new section takes over all settings of the previous one, including its headers and footers, and you change what should differ.
- **New page or new line.** A section that begins on a new page can have its own page size and headers and footers. A section that begins on a new line changes the number of columns, for example, without a page break.

### Set Up Pages in the Ribbon

The **Page Layout** tab, a [RibbonPageLayoutTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonpagelayouttab/llms-full.txt), works on the section with the input position:

| Group | Commands |
|---|---|
| **Page Setup** | **Margins** opens the page setup dialog box for the section or the whole document; **Orientation** (**Portrait**, **Landscape**) and **Size** set the pages of the current section |
| **Columns & Breaks** | **Columns** (**One**, **Two**, **Three**, **More Columns...**); **Breaks** with **Page Breaks** (**Page**, **Column**, **Text Wrapping**) and **Section Breaks** (**Next Page**, **Continuous**) |
| **Page Background & Frames** | **Page Color**, and **Frame**, **Frame Color** and **Frame Width** for a border around the pages of the section |

**Next Page** inserts a section break after which the new section begins on a new page, **Continuous** one after which it continues on the next line:

![TX Text Control Words with the Page Layout tab and the Breaks menu open, listing Page, Column and Text Wrapping under Page Breaks and Next Page and Continuous under Section Breaks, above a second page whose header is labeled Header - Section 2.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/page-layout-tab-breaks.8feb27a7.webp)

The status bar shows the new section as **Section: 2/2**, and a header of the new section is labeled with its section number.

The **Page Setup** dialog box has the tabs **Margins and Paper**, **Headers and Footers**, **Columns** and **Frames**. On **Margins and Paper**, **Section start** sets whether the section begins on a new page, and **Apply to** chooses between the **Whole document** and the current **Section**:

![The Page Setup dialog box on its Margins and Paper tab, with margins, paper format A4, width and height, portrait and landscape orientation, the Section start list set to New page and the Apply to list open with Whole document and Section.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/page-setup-margins-paper.81fbf900.webp)

[SectionFormatDialog](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/sectionformatdialog-method/llms-full.txt) opens the dialog box from code. The zero-based tab index is 0 for margins, page size and orientation, 1 for headers and footers, 2 for page columns and 3 for page borders.

### Insert a Section Break From Code

The following methods insert a section in landscape orientation at the input position and open the page setup:

```csharp
using System;
using System.Windows.Forms;
using TXTextControl;

public partial class Form1 : Form
{
    private void InsertLandscapeSection()
    {
        // A section break at the input position; the new section begins on a new page
        if (textControl1.Sections.Add(SectionBreakKind.BeginAtNewPage))
        {
            // The input position is now in the new section
            Section section = textControl1.Sections.GetItem();
            section.Format.Landscape = true;
        }
    }

    private void ShowPageSetup()
    {
        // 0 opens the tab with margins, page size and orientation
        textControl1.SectionFormatDialog(0);
    }
}
```

The code works as follows:

- [TextControl.Sections](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/sections-property/llms-full.txt) returns the [SectionCollection](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/llms-full.txt). [Add](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/add-method/llms-full.txt) inserts a section break at the input position, with `BeginAtNewPage` or `BeginAtNewLine` from [SectionBreakKind](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionbreakkind/enumeration/llms-full.txt), and returns `true` if it was added. A break inside a paragraph splits it in two.
- [SectionCollection.GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/getitem-method/llms-full.txt) without a parameter returns the section with the input position, which after `Add` is the new one.
- [Section.Format](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/section/format-property/llms-full.txt) returns the [SectionFormat](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/llms-full.txt) of the section, and [Landscape](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/landscape-property/llms-full.txt) turns its pages. The sections after it inherit the orientation, so set `Landscape` back to `false` in the section where portrait pages continue.
- `textControl1.Sections[2]` returns a section by its number through the [indexer](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/item-property/llms-full.txt), for code that formats a section other than the one with the input position.
- `SectionFormatDialog(0)` opens the **Margins and Paper** tab.

### Format a Section

A `SectionFormat` holds the page settings of one section:

| Property | Sets |
|---|---|
| [Landscape](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/landscape-property/llms-full.txt) | Landscape or portrait orientation |
| [PageSize](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/pagesize-property/llms-full.txt), [PageMargins](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/pagemargins-property/llms-full.txt) | The paper size, always as the values in portrait orientation, and the margins |
| [BreakKind](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/breakkind-property/llms-full.txt) | Whether the section begins on a new page, the default, or on a new line |
| [Columns](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/columns-property/llms-full.txt), [ColumnLineWidth](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/columnlinewidth-property/llms-full.txt) | The number of page columns, 1 by default, and a line between them |
| [PageBorder](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/pageborder-property/llms-full.txt) | A border around the pages, as a [PageBorder](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/pageborder/llms-full.txt) |
| [RestartPageNumbering](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionformat/restartpagenumbering-property/llms-full.txt) | Whether page numbers start again in this section |

Page sizes and margins are measured in the unit of [TextControl.PageUnit](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/pageunit-property/llms-full.txt), 1/100 inch by default, and column widths, lines and page borders in twips. [Selection.SectionFormat](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selection/sectionformat-property/llms-full.txt) reads and sets the settings of the selected text; when the selection spans sections with different settings, `Columns` returns 0. [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/sections-headers/llms-full.txt) shows columns, margins and page borders in code.

### Show the Current Section

The `StatusBar` of TX Text Control shows the section of the input position. Your own label can do the same with the [SectionChanged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/sectionchanged-event/llms-full.txt) event, which occurs when the input position moves to another section:

```csharp
private void ShowSectionNumber()
{
    textControl1.SectionChanged += (sender, e) =>
    {
        // Sections are numbered from 1
        sectionLabel.Text = $"Section {textControl1.InputPosition.Section} of {textControl1.Sections.Count}";
    };
}
```

`sectionLabel` is a `Label` on your form. Call `ShowSectionNumber` once, for example in the constructor of the form. [InputPosition.Section](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/inputposition/section-property/llms-full.txt) is the number of the section with the input position, and `Sections.Count` the number of sections.

### Set the Page Format of the Whole Document

[TextControl.PageSize](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/pagesize-property/llms-full.txt), [PageMargins](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/pagemargins-property/llms-full.txt) and [Landscape](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/landscape-property/llms-full.txt) set the page format of all sections at once; [Set the Page Format](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/creating/#set-the-page-format) shows them in code. A [PageSize](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/pagesize/llms-full.txt) takes the width and height in 1/100 inch, for example `new PageSize(827, 1169)` for A4, and [ResetPageSize](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/resetpagesize-method/llms-full.txt) returns to the default, US letter. When the page settings change, the control raises [PageFormatChanged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/pageformatchanged-event/llms-full.txt). To make a document with several sections a document with one page layout, delete its section breaks, as [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/sections-headers/#remove-all-section-breaks) shows.

### Next Steps

- [Headers and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/headers-footers/llms-full.txt): give a section its own header and restart page numbers.
- [Tables and Table Formulas](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/tables/llms-full.txt): fill the landscape page with a wide table.
- [Printing and Print Preview](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/printing/llms-full.txt): print the pages you set up.
- [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/sections-headers/llms-full.txt): sections with `ServerTextControl`.

---

## Nearby

- **Previous:** [Headers and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/headers-footers/llms-full.txt)
- **Next:** [Footnotes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/footnotes/llms-full.txt)
