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

Paragraphs

  • 3 minutes to read

The Paragraph class represents paragraphs in the RichEditControl. You can manage them in code and using the User Interface

Paragraphs in the User Interface

End-users can press Enter to divide text into paragraphs, and the Paragraph group on the Home ribbon tab allows them to format paragraphs. Refer to the How to: Create the RichEditControl with a Ribbon UI lesson for information on how to provide a Ribbon UI for the RichEditControl.

RichEdit_Ribbon_Paragraph

End-users can specify advanced paragraph settings using the Paragraph Dialog. You can invoke this dialog from the ribbon group or from the context menu.

RichEdit_ShowParagraphDialog_RibbonCaptionButton

RTEParagraphContextMenu

Tip

You can restrict end-users from formatting paragraphs or creating new paragraphs. Set the DocumentCapabilitiesOptions.Paragraphs, DocumentCapabilitiesOptions.ParagraphFormatting, or DocumentCapabilitiesOptions.ParagraphTabs property to DocumentCapability.Hidden or DocumentCapability.Disabled to disable or hide the corresponding commands in the Ribbon UI and the pop-up menu.

The RichEditControl can display, print and export to PDF format documents with paragraph borders.

XtraRichEdit_ParagraphBorders

Note

The control does not provide user interface elements to create or modify paragraph borders.

Paragraphs in Code

The ParagraphCollection contains all document paragraphs. Access a specific paragraph by it index using the SubDocument.Paragraphs property. You can also retrieve the paragraph related to the given range using the ReadOnlyParagraphCollection.Get method.

Use one of the following methods to insert new paragraph:

Paragraphs can be formatted directly or using document styles. Refer to the Text Formatting topic for more information.

Note

The RichEditControl does not provide an API to manage paragraph borders.

The code sample below shows how to change paragraph formatting in code:

Note

A complete sample project is available at: WinForms RichEdit Document API

document.BeginUpdate();
document.AppendText("Modified Paragraph\nNormal\nNormal");
document.EndUpdate();

//The target range is the first paragraph
DocumentPosition pos = document.Range.Start;
DocumentRange range = document.CreateRange(pos, 0);

// Create and customize an object  
// that sets character formatting for the selected range
ParagraphProperties pp = document.BeginUpdateParagraphs(range);
// Center paragraph
pp.Alignment = ParagraphAlignment.Center;
// Set triple spacing
pp.LineSpacingType = ParagraphLineSpacing.Multiple;
pp.LineSpacingMultiplier = 3;
// Set left indent at 0.5".
// Default unit is 1/300 of an inch (a document unit).
pp.LeftIndent = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.5f);
// Set tab stop at 1.5"
TabInfoCollection tbiColl = pp.BeginUpdateTabs(true);
TabInfo tbi = new DevExpress.XtraRichEdit.API.Native.TabInfo();
tbi.Alignment = TabAlignmentType.Center;
tbi.Position = DevExpress.Office.Utils.Units.InchesToDocumentsF(1.5f);
tbiColl.Add(tbi);
pp.EndUpdateTabs(tbiColl);

//Finalize modifications
// with this method call
document.EndUpdateParagraphs(pp);

Note

We recommend using the ParagraphProperties options to format paragraphs instead of specifying the formatting options directly to the Paragraph object. Use the Paragraph object’s properties to check the information.

See Also