# Hyphenation With TX Text Control

> Turn on hyphenation in a Windows Forms TextControl with SpellChecker and IsHyphenationEnabled, set text languages, and change divisions in HyphenateWord.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > Hyphenation > Hyphenation With TX Text Control
- **1998 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/tx-text-control/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/tx-text-control/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/tx-text-control/llms-full.txt

---

In a TX Text Control editor, TX Spell .NET divides the last word of a full line and moves the rest to the next line, as the user types and in every language that has a hyphenation list. Turning this on takes two properties. The sections below show what the user sees, how the language of the text chooses the rules, and how your code can change where a word is divided.

### What the User Sees

Once hyphenation is on, a word that doesn't fit at the end of a line is no longer moved to the next line as a whole. It is divided at a hyphenation point, and a hyphen marks the division:

![TX Text Control Words with a document whose lines end in divided words such as Win-dows, prop-erties and documenta-, with the Enable Hyphenation button of the ribbon switched on.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/hyphenation-in-words.f868d4d5.webp)

The division follows the text as it changes. While the user types, the word at the end of the line is divided as soon as it reaches the margin:

![Text being typed before the last word of a line in TX Text Control Words, which divides the word hyphenation as hyphen- when it reaches the right margin.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/hyphenation-while-typing.5963cca7.webp)

Both pictures show TX Text Control Words, the demo application of TX Text Control, in an earlier version of its ribbon.

### How It Works

Two properties of the `TextControl` are needed:

- [SpellChecker](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/spellchecker-property/llms-full.txt) connects a [TXSpellChecker](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/llms-full.txt). The same connection serves spell checking, as [As-You-Type Checking](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/as-you-type/llms-full.txt) shows.
- [IsHyphenationEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/ishyphenationenabled-property/llms-full.txt) turns hyphenation on.

When a word doesn't fit into a line, the spell checker calculates where to divide it, from the hyphenation list of the word's language. The `TextControl` then raises its [HyphenateWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/hyphenateword-event/llms-full.txt) event with that position, divides the word there and puts a hyphen at the end of the line.

### Turn On Hyphenation

In the designer, select the `TextControl` and set its properties in the **Properties** window:

1. Set **SpellChecker** to `txSpellChecker1`, the `TXSpellChecker` on the form.
2. Set **IsHyphenationEnabled** to **True**.

![The Properties window of textControl1 with IsHyphenationEnabled set to True and the drop-down of IsSpellCheckingEnabled open with True and False.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/properties-hyphenation-on.1be9c6d4.webp)

The same in code, for example in the constructor of the form after `InitializeComponent`:

```csharp
// Connect the spell checker and hyphenate words at the end of a line
textControl1.SpellChecker = txSpellChecker1;
textControl1.IsHyphenationEnabled = true;
```

Run the application and type a long text: the last word of each line is divided when it doesn't fit. [Create Your First Windows Forms Application](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/tx-text-control/first-application/llms-full.txt) sets up such an application from the start.

### Switch Hyphenation On and Off in the Ribbon

With the ribbon of TX Text Control, users switch hyphenation on and off themselves. The **Enable Hyphenations** button is on the **Proofing** tab, a [RibbonProofingTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonproofingtab/llms-full.txt), in the **Spelling & Hyphenation** group:

![The Proofing tab of the ribbon with the buttons Enable Spell Checking, Enable Hyphenations, Thesaurus, Spelling, Load Dictionary, Load Thesaurus File and Manage Spelling & Hyphenation.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/ribbon-proofing-tab.748b5cc8.webp)

Except for the language button, the buttons of the tab are enabled only when the `TextControl` has a spell checker connected through `SpellChecker`.

### Which List Hyphenates Which Text

Every part of a document can have a language of its own, and each word is hyphenated with the hyphenation list of its language. A document with English and German paragraphs therefore needs *hyph\_en\_US.dic* and *hyph\_de\_DE.dic* in the *HyphenationLists* folder; [Hyphenation Lists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/lists/llms-full.txt) shows where to get them.

The user sets the language of the text in the **Language** dialog of TX Text Control, your code with the `Culture` of the selection or of a style, and language detection sets it for text without one; [How Text Gets a Language](https://docs.textcontrol.com/tx-spell-dotnet-winforms/dictionaries/multilingual/#how-text-gets-a-language) describes the three ways.

The [HyphenationLanguage](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/hyphenationlanguage-property/llms-full.txt) property of the spell checker selects its default list. With its default value `"(Auto)"`, it follows the language of the spell check dictionary. The settings of each list, such as the fewest characters on each line, are changed by the user on the **Hyphenation** tab of the [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/#the-hyphenation-and-thesaurus-tabs), and in code as [Hyphenation Lists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/lists/#change-how-words-are-divided) shows.

### Change Where a Word Is Divided

The `HyphenateWord` event lets your code look at each division and change it. Its [HyphenateWordEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/llms-full.txt) hold:

| Property | Contents |
|---|---|
| [Word](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/word-property/llms-full.txt) | The word that doesn't fit into the line |
| [Culture](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/culture-property/llms-full.txt) | The language of the word |
| [MaxDividePos](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/maxdividepos-property/llms-full.txt) | The largest position at which the word can be divided: with 3, at most the first three characters fit into the line |
| [DividePos](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/hyphenatewordeventargs/dividepos-property/llms-full.txt) | The position the spell checker calculated. Set it to divide the word elsewhere |

The `TextControl` divides the word at `DividePos` if it is not greater than `MaxDividePos`. This handler logs each division, which shows how the rules of a list work on your documents:

```csharp
private void textControl1_HyphenateWord(object sender, TXTextControl.HyphenateWordEventArgs e)
{
    System.Diagnostics.Debug.WriteLine(
        $"{e.Word} ({e.Culture}): divided after {e.DividePos} of at most {e.MaxDividePos} characters");
}
```

Attach it in the constructor with `textControl1.HyphenateWord += textControl1_HyphenateWord;`, or in the **Events** view of the **Properties** window. To divide a word by other rules, assign another position to `DividePos`. [GetHyphenationPoint](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/gethyphenationpoint-method/llms-full.txt) of the spell checker returns the last hyphenation point before a position, with the list of any language. This handler divides every word by the British English rules of *hyph\_en\_GB.dic*, which must be in the *HyphenationLists* folder:

```csharp
private void textControl1_HyphenateWord(object sender, TXTextControl.HyphenateWordEventArgs e)
{
    // Divide with the British English list, before the margin
    e.DividePos = txSpellChecker1.GetHyphenationPoint(e.Word, e.MaxDividePos, new System.Globalization.CultureInfo("en-GB"));
}
```

[Hyphenating Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/in-code/llms-full.txt) explains `GetHyphenationPoint` and what it returns.

### Next Steps

- [Hyphenation Lists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/lists/llms-full.txt): the files behind hyphenation, and their settings.
- [Hyphenating Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/in-code/llms-full.txt): hyphenation points without a `TextControl`.
- [Multilingual Documents and Language Scopes](https://docs.textcontrol.com/tx-spell-dotnet-winforms/dictionaries/multilingual/llms-full.txt): documents in more than one language.
- [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/options-dialog/llms-full.txt): the hyphenation settings users change.

---

## Nearby

- **Previous:** [Hyphenation Lists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/lists/llms-full.txt)
- **Next:** [Hyphenating Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/hyphenation/in-code/llms-full.txt)
