Edit this page

Spellcheck

The RadRichTextBox 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

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

You can customize the spell checker by using the SpellChecker property of RadRichTextBox. 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.

Dictionaries

The dictionaries in RadRichTextBox implement the IWordDictionary interface. Easy interoperability with dictionaries from RadSpell for ASP.NET is achieved through the WordDictionary class, which supports the loading of a dictionary directly from the *.tdf files, used with RadSpell.

Here is an example of a WordDictionary loaded from a TDF file.

note

When adding a WordDictionary 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 .

Load dictionary

private void LoadDictionary(Stream tdfFileStream)
{
    WordDictionary dictionary = new WordDictionary();
    dictionary.Load(tdfFileStream);
    ((DocumentSpellChecker)this.radRichTextBox1.SpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture);
}

Private Sub LoadDictionary(ByVal tdfFileStream As Stream)
    Dim dictionary As New WordDictionary()
    dictionary.Load(tdfFileStream)
    CType(Me.RadRichTextBox1.SpellChecker, DocumentSpellChecker).AddDictionary(dictionary, CultureInfo.InvariantCulture)
End Sub

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 done 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:

Add word to dictionary

this.radRichTextBox1.SpellChecker.AddWord("RadRichTextBox", CultureInfo.InvariantCulture);

Me.RadRichTextBox1.SpellChecker.AddWord("RadRichTextBox", 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).

note

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

Load international dictionary

private void LoadDictionaryDE(Stream tdfFileStream)
{
     WordDictionary dictionary = new WordDictionary();
    dictionary.Load( tdfFileStream );
    (( DocumentSpellChecker )this.radRichTextBox1.SpellChecker ).AddDictionary( dictionary, new CultureInfo( "de-DE" ));
}

Private Sub LoadDictionaryDE(ByVal tdfFileStream As Stream)
    Dim dictionary As New WordDictionary()
    dictionary.Load(tdfFileStream)
    CType(Me.RadRichTextBox1.SpellChecker, DocumentSpellChecker).AddDictionary(dictionary, New CultureInfo("de-DE"))
End Sub

Was this article helpful? Yes No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy