# Spellcheck

The **RadRichTextEditor** control is designed to support "*spell checking as you type*" by setting a single property and specifying a proper dictionary to it. This topic will explain you the following:

* [Enabling SpellCheck](https://www.telerik.com/products/winforms/documentation/controls/richtexteditor/features/spellcheck#enabling-spellcheck)

* [Dictionaries](https://www.telerik.com/products/winforms/documentation/controls/richtexteditor/features/spellcheck#dictionaries)

* [Custom Dictionaries](https://www.telerik.com/products/winforms/documentation/controls/richtexteditor/features/spellcheck#custom-dictionaries)

* [Adding a Word](https://www.telerik.com/products/winforms/documentation/controls/richtexteditor/features/spellcheck#adding-a-word)

* [Internationalization](https://www.telerik.com/products/winforms/documentation/controls/richtexteditor/features/spellcheck#internationalization)

## Enabling SpellCheck

To enable or disable the spell checking functionality (present as red wavy underlines below unrecognized words), you can use the **IsSpellCheckingEnabled** property on **RadRichTextEditor**. When the property is *false*, no dictionaries are loaded and no overhead is incurred for spell checking.

> caption Figure 1: Spell Checking as you type

![WinForms RadRichTextEditor Spell checking as you type](https://www.telerik.com/products/winforms/documentation/assets/51cfc4ad9939dffb6edb443a91fec2ef/richtexteditor-features-spellcheck001.png)

You can customize the spell checker by using the **SpellChecker** property of **RadRichTextEditor**. It’s of type **ISpellChecker**. By default, an object of type **DocumentSpellChecker** that implements the interface, is used for this property. You can either use it or provide your custom class that implements the **ISpellChecker** interface.

When you right click a misspelled word, the context menu gives you the opportunity to open a **SpellCheckingDialog**. Thus, the user can correct the word, add it to the dictionary or ignore it.

> note Since R2 2017 SP the SpellCheckingDialog allows the user to enter some custom text by using a RadTextBox if no appropriate word exist in the offered list.

> caption Figure 2: Spell checking dialog

![WinForms RadRichTextEditor Spell checking dialog](https://www.telerik.com/products/winforms/documentation/assets/c1deb913519fbf9ffa272e83bbf5d68c/richtexteditor-features-spellcheck002.png)

> note **RadRichTextEditor** can also be configured to be used with a spell-checker using an OpenOffice dictionary and the NHunspell library: [RadRichTextEditor OpenOffice Spell Checking](http://www.telerik.com/support/code-library/radrichtexteditor-openoffice-spell-checking).

## Dictionaries

The dictionaries in **RadRichTextEditor** implement the **IWordDictionary** interface. Easy interoperability with dictionaries from **RadSpell** for ASP.NET is achieved through the **RadDictionary** class, which supports the loading of a dictionary directly from the \*.tdf files, used with **RadSpell**. You can find TDF dictionaries for some languages [here](http://www.telerik.com/support/code-library/dictionaries-for-radspellchecker).

Here is an example of a **RadDictionary** loaded from a TDF file.

> note When adding a **RadDictionary** or similar object use the **AddDictionary(IWordDictionary dictionary, CultureInfo culture)** method of the **DocumentSpellChecker** . You can also associate a dictionary with a specific culture. The method to remove this dictionary is **RemoveDictionary(CultureInfo culture)** .

> note The given example doesn't contain the logic used to read the **TDF** file as a **Stream** .

```C#
private void LoadDictionary1(Stream tdfFileStream)
{
    RadDictionary dictionary = new RadDictionary();
    dictionary.Load(tdfFileStream);
    ((DocumentSpellChecker)this.radRichTextEditor1.SpellChecker).AddDictionary(dictionary, new CultureInfo("de-DE"));
}

```

```VB.NET
    Private Sub LoadDictionary1(ByVal tdfFileStream As Stream)
        Dim dictionary As New RadDictionary()
        dictionary.Load(tdfFileStream)
        CType(Me.radRichTextEditor1.SpellChecker, DocumentSpellChecker).AddDictionary(dictionary, New CultureInfo("de-DE"))
    End Sub

```

## RadWordsDictionary

**RadWordsDictionary** implements the **IWordDictionary** interface and is capable of reading words from text files that contain one word per line. An example of such files are the **.dic** dictionaries.

#### Load stream in RadWordsDictionary

```C#
private void LoadWordDictionaryStream(Stream dictStrem)
{
    Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary dictionary = new Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary();
    dictionary.Load(dictStrem);
}
```

```VB.NET
    Private Sub LoadWordDictionaryStream(dictStrem As Stream)
        Dim dictionary As New Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary()
        dictionary.Load(dictStrem)
    End Sub
```

One of the constructor overloads of the **RadWordsDictionary** class enables you to pass a parameter of type **IEnumerable\<string>**, which can help you create your own dictionary with a custom set of words.

#### Create RadWordsDictionary from strings

```C#
private void LoadWordDictionaryStream()
{
    List<string> words = new List<string>();
    words.Add("Test");
    words.Add("Teacher");
    words.Add("Sister");

    Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary dictionary = new Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary();
    dictionary.Load(words);
}
```

```VB.NET
    Private Sub LoadWordDictionaryStream()
        Dim words As New List(Of String)()
        words.Add("Test")
        words.Add("Teacher")
        words.Add("Sister")

        Dim dictionary As New Telerik.WinControls.SpellChecker.Proofing.RadWordsDictionary()
        dictionary.Load(words)
    End Sub
```

## Custom Dictionaries

One feature of the **SpellChecker** in **RadRichTextEditor** is to add a word to a user-defined custom dictionary to enable domain-specific applications. Such dictionary should implement the **IWordCustomDictionary** interface. For that purpose the **RadRichTextEditor** provides you with the **RadIsolatedStorageCustomDictionary** class out of the box. It allows you to persist the word list in a file located in the Isolated Storage.

Here is an example of a such dictionary which adds the words in the "CustomDictionary.txt" marked as a Site-scoped **IsolatedSotrageFile**.

> tip The **IsolatedStorageScope** enumeration has the following values:
>
> * **Site** - the dictionary defined in this scope is available for each application hosted on the same site.
> * **Application** - the dictionary is available only for the particular application.>

> note When adding a dictionary that implements the **ICustomWordDictionary** interface object use **AddCustomDictionary(ICustomWordDictionary customDictionary, CultureInfo culture)** method for the **DocumentSpellChecker** class. You can also associate a custom dictionary to a specific culture. The method to remove it is **RemoveCustomDictionary(ICustomWordDictionary customDictionary, CultureInfo culture)** .

```C#
private void CreateCustomDictionary()
{
    RadIsolatedStorageCustomDictionary dictionary = new RadIsolatedStorageCustomDictionary(IsolatedStorageScope.Site, "CustomDictionary.txt");
    DocumentSpellChecker spellchecker = new DocumentSpellChecker(dictionary);
    this.radRichTextEditor1.SpellChecker = spellchecker;
}

```

```VB.NET
    Private Sub CreateCustomDictionary()
        Dim dictionary As New RadIsolatedStorageCustomDictionary(IsolatedStorageScope.Site, "CustomDictionary.txt")
        Dim spellchecker As New DocumentSpellChecker(dictionary)
        Me.radRichTextEditor1.SpellChecker = spellchecker
    End Sub

```

If you want to have a temporary custom dictionary, that will only be available for a single application session, you can use the **RadNonPersistentCustomDictionary** object.

## Adding a Word

To add a word to a dictionary you can either use the **AddWord** method of the **DocumentSpellChecker** or of the dictionary itself. Using the first one you can add a word to multiple dictionaries associated to the same culture. This is done by passing the desired culture as parameter to the method.

> note Using the overload of the **AddWord** method that takes only the word as argument is equal to using the second overload and passing **CultureInfo.InvariantCulture** as argument.

Using the **AddWord** method of the dictionary itself will add the word only to the respective dictionary.

Here is an example.

```C#
this.radRichTextEditor1.SpellChecker.AddWord("RadRichTextEditor", CultureInfo.InvariantCulture);

```

```VB.NET
Me.radRichTextEditor1.SpellChecker.AddWord("RadRichTextEditor", CultureInfo.InvariantCulture)

```

## Internationalization

The spell checking component is designed to suit scenarios where different cultures take place in the same application. Internationalization is achieved through associating each dictionary and custom dictionary with a specific culture (or the **InvariantCulture** as the default one).

Here is an example.

> note The given example doesn't contain the logic used to read the **TDF** file as a **Stream** .

```C#
private void LoadDictionary1(Stream tdfFileStream)
{
    RadDictionary dictionary = new RadDictionary();
    dictionary.Load(tdfFileStream);
    ((DocumentSpellChecker)this.radRichTextEditor1.SpellChecker).AddDictionary(dictionary, new CultureInfo("de-DE"));
}

```

```VB.NET
    Private Sub LoadDictionary1(ByVal tdfFileStream As Stream)
        Dim dictionary As New RadDictionary()
        dictionary.Load(tdfFileStream)
        CType(Me.radRichTextEditor1.SpellChecker, DocumentSpellChecker).AddDictionary(dictionary, New CultureInfo("de-DE"))
    End Sub

```

## See Also

* [How to Extract the Words Added to the Dictionary in RadSpellChecker](https://www.telerik.com/products/winforms/documentation/knowledge-base/extract-words-added-to-dictionary)
* [How to Share Localization Providers and Spell Checking Dictionaries](https://www.telerik.com/products/winforms/documentation/knowledge-base/share-localization-providers-and-dictionaries)
