Skip to main content
A newer version of this page is available. .

Sections

  • 4 minutes to read

The DXRichEdit provides the following ways to manage document sections:

Sections in the User Interface

End-users can insert section breaks and set the page layout options using the Page Layout ribbon tab. Refer to the Lesson 1 - Create a Simple Rich Text Editor topic for information on how to add a Ribbon UI to the RichEditControl.

DXRichEdit_Ribbon_PageLayout

The RichEditControl ships with the Page Setup Dialog. This dialog allows end-users to define a page’s formatting options of a whole document or a particular section.

Tip

Set the DXRichEditDocumentCapabilitiesOptions.Sections property to Hidden or Disabled to restrict end-users from managing document sections.

Divide a Document into Sections

The Document.Sections property provides access to the document’s section collection. Use the following methods to insert a section in code:

//Append an empty section:
richEditControl.Document.AppendSection();

//Insert a section at the document start:
 richEditControl.Document.InsertSection(richEditControl.Document.Range.Start);

Specify the Section.StartType property to define the section break’s type. The RichEditControl supports the following section breaks:

  • Next Page - starts the new section on the following page.
  • Continuous - starts the new section on the same page.
  • Even Page - starts a new section on the next even-numbered page.
  • Odd Page - starts a new section on the next odd-numbered page.
  • Column - starts a new section on the next column on the page.

Use the DXRichEditBehaviorOptions.PageBreakInsertMode property to specify whether a page break is inserted next to the specified position or in the new line.

Execute one of the following commands to insert a specific section break:

Command Description
InsertSectionBreakEvenPageCommand Inserts an Even Page section break.
InsertSectionBreakNextPageCommand Inserts a Next Page section break.
InsertSectionBreakOddPageCommand Inserts a Odd Page section break.
InsertSectionBreakContinuousCommand Inserts a Continuous section break.
InsertSectionBreakColumnCommand Inserts a Column section break.

Define Page Formatting Options

Each section has page formatting options. You can use the SectionPage class properties to specify the page’s paper type, orientation, margins, etc. Use the Section.Page property to access the SectionPage object .

The code sample below specifies the first section’s page formatting options: sets the portrait orientation and the A3 Extra paper size.

Section firstSection =  richEditControl1.Document.Sections[0];
firstSection.Page.Landscape = false;
firstSection.Page.PaperKind = System.Drawing.Printing.PaperKind.A3Extra;

The RichEditControl provides the following commands to modify page formatting settings:

Command Description
SetModerateSectionPageMarginsCommand Sets the top and bottom margins at one inch and the lateral margins at .75 inches.
SetNarrowSectionPageMarginsCommand Sets all margins at half-an-inch.
SetNormalSectionPageMarginsCommand Sets all margins at one inch.
SetWideSectionPageMarginsCommand Sets vertical margins at one inch and side margins at two inches.
SetSectionOneColumnCommand Sets the section to have only one column.
SetSectionTwoColumnsCommand Sets the section to have two columns.
SetSectionThreeColumnsCommand Sets the section to have three columns.

Line Numbering

Set the SectionLineNumbering.CountBy property to a non-zero value to enable line numbering. Refer to the Line Numbering topic for more information.

Columns

Call the SectionColumns.CreateUniformColumns method to create a multi-column layout. Refer to the How to: Create a Three-Column Layout with Uniform Columns topic for more information.

Page Numbering

Each document section has its own page numbering settings (page number format, initial number, etc.). Use the Section.PageNumbering property to access the SectionPageNumbering class properties and specify section’s page numbering options. You should reset the numbering options by setting the SectionPageNumbering.ContinueNumbering property to false before you apply new options. The PAGE field represents a document’s page number. To apply new settings to existing page numbers, call the FieldCollection.Update method to update all fields.

The code sample below specifies the initial number and the NumberingFormat.CardinalText numbering format.

![dxrichedit_page_numbering](~/images/dxrichedit_page _numbering.png)

richEditControl1.Document.Sections[0].PageNumbering.ContinueNumbering = false;
richEditControl1.Document.Sections[0].PageNumbering.FirstPageNumber = 3;
richEditControl1.Document.Sections[0].PageNumbering.NumberingFormat = NumberingFormat.CardinalText;
richEditControl1.Document.Fields.Update();

Headers and Footers

Headers and footers in the document belong to a particular section. You can use the Section.BeginUpdateHeader - Section.EndUpdateHeader and the Section.BeginUpdateFooter - Section.EndUpdateHeader method pairs to edit header or footer content. Refer to the Headers and Footers topic for more information.

See Also