Back to Devexpress

Hyphenation in Rich Text Documents

windowsforms-401190-controls-and-libraries-rich-text-editor-hyphenation.md

latest6.5 KB
Original Source

Hyphenation in Rich Text Documents

  • Sep 20, 2025
  • 3 minutes to read

The RichEditControl can enable or suppress word hyphenation at line breaks.

When you load a document, the following scenarios are possible:

  • If the document contains soft hyphens, RichEditControl preserves them.
  • If the document has automatic hyphenation enabled, the RichEditControl uses the currently linked hyphenation dictionaries to hyphenate the text. Note that the document layout may change.

Add a Hyphenation Dictionary

Link a dictionary that specifies hyphenation rules. The RichEditControl.HyphenationDictionaries property provides access to the dictionary collection. You can use two dictionary types:

OpenOfficeHyphenationDictionary The OpenOffice hyphenation dictionary is a .dic file containing hyphenation patterns with specific encoding. The file can contain the following information:

  • LEFTHYPHENMIN - The minimum number of characters that must appear before the first hyphen.
  • RIGHTHYPHENMIN - The minimum number of characters that must appear after the last hyphen.

Use the LeftHyphenMin and RightHyphenMin properties to change these parameters.

You can download dictionaries from https://extensions.openoffice.org/. Note that the OpenOffice license cannot be used for commercial projects.

CustomHyphenationDictionary A file with hyphenation patterns. It can contain a list of words divided into syllables (e.g., hy-phe-na-tion).

The code sample below shows how to add hyphenation dictionaries:

View Example: How to Link Hyphenation Dictionaries

csharp
//Load embedded dictionaries
var openOfficePatternStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.hyphen.dic");
var customDictionaryStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.hyphen_exc.dic");

//Create dictionary objects
CustomHyphenationDictionary exceptionsDictionary = new CustomHyphenationDictionary(customDictionaryStream, new System.Globalization.CultureInfo("EN-US"));
OpenOfficeHyphenationDictionary hyphenationDictionary = new OpenOfficeHyphenationDictionary(openOfficePatternStream, new System.Globalization.CultureInfo("EN-US"));

//Add them to the word processor's collection
richEditControl.HyphenationDictionaries.Add(exceptionsDictionary);
richEditControl.HyphenationDictionaries.Add(hyphenationDictionary);
vb
' Load embedded dictionaries
Dim openOfficePatternStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.hyphen.dic")
Dim customDictionaryStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ConsoleApp1.hyphen_exc.dic")

'Create dictionary objects
Dim hyphenationDictionary As OpenOfficeHyphenationDictionary = New OpenOfficeHyphenationDictionary(openOfficePatternStream, New System.Globalization.CultureInfo("EN-US"))
Dim exceptionsDictionary As CustomHyphenationDictionary = New CustomHyphenationDictionary(customDictionaryStream, New System.Globalization.CultureInfo("EN-US"))

'Add them to the word processor's collection
richEditControl.HyphenationDictionaries.Add(exceptionsDictionary)
richEditControl.HyphenationDictionaries.Add(hyphenationDictionary)

Dictionary Culture

The RichEditControl uses dictionaries that match the document’s culture. You can specify the dictionary’s culture in the object constructor. If the culture is not specified, the dictionary’s culture is set to the machine’s current culture.

Hyphenate Text

Use the following properties to hyphenate document text:

PropertyDescription
Document.HyphenationSpecifies whether to hyphenate text automatically. If dictionaries are not provided, the property has no effect.
Document.HyphenateCapsGets or sets whether to hyphenate words in CAPS.
Paragraph.SuppressHyphenationSpecifies whether to limit hyphenation to a specific paragraph.

The code sample below shows how to enable hyphenation and export a document to the PDF format.

csharp
//Load a document
richEditControl.LoadDocument("Grimm.docx");

//Specify hyphenation settings
richEditControl.Document.Hyphenation = true;
richEditControl.Document.HyphenateCaps = true;

//Export the result to the PDF format
richEditControl.ExportToPdf("Result.pdf");

//Open the result
Process.Start("Result.pdf");
vb
'Load a Document
richEditControl.LoadDocument("Grimm.docx")

'Specify hyphenation settings
richEditControl.Document.Hyphenation = True
richEditControl.Document.HyphenateCaps = True

'Export the result to the PDF format
richEditControl.ExportToPdf("Result.pdf")

'Open the result
Process.Start("Result.pdf")

Hyphenation in the User Interface

End user can press Ctrl+- to insert soft hyphens where necessary. Use the Hyphenation drop-down list on the Page Layout ribbon tab to enable or suppress automatic hyphenation, and specify additional hyphenation options. If dictionaries are not provided, the list is disabled.

The Hyphenation Dialog allows you to enable automatic hyphenation and specify whether to hyphenate words in CAPS.

Use the Paragraph Dialog to suppress hyphenation for a specific paragraph. On the Line and Page Breaks tab, check the Don’t Hyphenate item.