Why Should You Integrate Syncfusion WinForms Spell Checker into Your Text Editor?
Tags: csharp, dotnet, productivity
Published: 2020-09-21 12:13:36

---
title: Why Should You Integrate Syncfusion WinForms Spell Checker into Your Text Editor?
published: true
date: 2020-09-21 10:00:51 UTC
tags: csharp, dotnet, productivity
canonical_url: https://www.syncfusion.com/blogs/post/why-should-you-integrate-syncfusion-winforms-spell-checker-into-your-text-editor.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/broni0llv078n3ogimgs.png
---

Syncfusion [WinForms Spell Checker](https://www.syncfusion.com/winforms-ui-controls/spell-checker) (SpellCheckerAdv) is used to check the spelling of text in WinForms applications using dictionary resources. It can be integrated with WinForms text editors to identify spelling mistakes in text and correct them. The control can ignore special words, add new terms to the dictionary, and use a custom dictionary to check spelling.

A text editor control is used for editing text, formatting content, finding and replacing text, and more.

You may ask, why should I integrate the Syncfusion WinForms Spell Checker in a text editor control?

With this spell checker, you can:

- [Load your own dictionaries for any language](#load-your-own-dictionary-for-any-language) (Hunspell, Ispell, OpenOffice etc.).
- [Switch among different cultures at runtime](#switching-language-cultures-at-runtime).
- [Get suggestions for fixing errors](#get-suggestions-for-fixing-error-words).
- [Ignore special expressions](#ignore-special-expressions).
- [Apply different visual styles](#configuring-visualstyle).

Let’s try using these features in the TextBox control by integrating the WinForms Spell Checker.

## Configuring SpellCheckerAdv in TextBox control

Follow these steps to configure Spell Checker within the TextBox control:

**Step 1:**  **Create the project**

Create a new Windows Forms project in Visual Studio.

**Step 2:**  **Add the control manually using code.**

Add the control manually in C#:

1. Add the following required assembly references to the project:

- Syncfusion.Tools.Base.dll
- Syncfusion.Tools.Windows.dll
- Syncfusion.Shared.Base.dll
- Syncfusion.Shared.Windows.dll
- Syncfusion.SpellChecker.Base.dll
- Syncfusion.Grid.Base.dll
- Syncfusion.Grid.Windows.dll

1. Include the namespace  **Syncfusion.**** Windows.Forms.Tools**.
```csharp
using Syncfusion.Windows.Forms.Tools;
```
2. Create the SpellCheckerAdv control instance.
```csharp
SpellCheckerAdv spellCheckerAdv1 = new SpellCheckerAdv();
```

**Step 3: Configure the SpellCheckerAdv in TextBox.**

1. In the WinForms project, create a class implementing the [ISpellCheckerAdvEditorTools](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.ISpellCheckerAdvEditorTools.html) interface.
```csharp
class TextBoxSpellEditor : ISpellCheckerAdvEditorTools 
{ 
/// <summary> 
/// Initializes the TextBoxBase control. 
/// </summary> 
private TextBoxBase textBox; 
/// <summary> 
/// Initializes the new instance of the TextBoxSpellEditor class. 
/// </summary> 
/// <param name="control"></param> 
public TextBoxSpellEditor(Control control) 
{ 
Control = control; 
} 
/// <summary> 
/// Gets or sets the control whose text is to be spell checked. 
/// </summary> 
public Control Control 
{ 
  get
  { 
   return textBox; 
  } 
  set
  { 
  textBox = value as TextBoxBase; 
  } 
} 
/// <summary> 
/// Gets or sets the current misspelled word. 
/// </summary> 
public string CurrentWord 
{ 
 get
  { 
   return textBox.Text; 
   } 
   set
   { 
    textBox.Text = value; 
   } 
} 
/// <summary> 
/// Gets or sets the text to be spell checked by the <see cref="SpellCheckerAdv"/> 
/// </summary> 
public string Text 
{ 
  get
   { 
   return textBox.Text; 
   } 
   set
   { 
   textBox.Text = value; 
    } 
} 
/// <summary> 
/// Gets or sets the control whose text is to be spell checked. 
/// </summary> 
public Control ControlToCheck 
{ 
 get
 { 
 return textBox; 
 } 
 set
 { 
  textBox = value as TextBoxBase; 
  } 
} 
/// <summary> 
/// Selects the word specified by the index.
/// </summary> 
/// <param name="selectionStart">Zero based index of the word in the text.</param> 
/// <param name="selectionLength">length of the word to be selected.</param> 
public void SelectText(int selectionStart, int selectionLength) 
{ 
 textBox.Select(selectionStart, selectionLength); 
} 
}
```
2. Create and add instances of RichTextBox (editor control to be spell checked) and Button to the form.
```csharp
RichTextBox richTextBox1 = new RichTextBox(); 
Button button1 = new Button(); 
 
this.richTextBox1.Text = resources.GetString("richTextBox1.Text"); 
this.button1.Text="Spell Check"; 
 
this.Controls.Add(this.button1); 
this.Controls.Add(this.richTextBox1);
```

![Output](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Output.png)

3. Create an instance of the TextBoxSpellEditor class by passing the RichTextBox instance as parameter to its constructor. Control and add it to the SpellCheckerAdv using the [PerformSpellCheckForControl ](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_PerformSpellCheckForControl_Syncfusion_Windows_Forms_Tools_ISpellCheckerAdvEditorTools_)method.
```csharp
TextBoxSpellEditor TextEditor = new TextBoxSpellEditor(this.richTextBox1);
this.spellCheckerAdv1.PerformSpellCheckForControl(TextEditor);
```
4. Finally, trigger the SpellCheckerAdv through the Click event of a button.
```csharp
private void buttonAdv1_Click(object sender, EventArgs e) 
{
  this.spellCheckerAdv1.SpellCheck(new SpellCheckerAdvEditorWrapper(this.richTextBox1)); 
}
```

Executing the project will result in output like the following screenshot.

![Text editor control with WinForms Spell Checker](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Text-editor-control-with-WinForms-Spell-Checker.png)<figcaption>Text editor control with WinForms Spell Checker</figcaption>

## Load your own dictionary for any language

You can add your own dictionary to the [SpellCheckerAdv.Dictionaries](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_Dictionaries) collection.

SpellCheckerAdv supports the following standard dictionary file formats:

- Hunspell
- Ispell
- OpenOffice

### Spell check using Hunspell dictionary

You can check spelling mistakes using Hunspell dictionary format, which contains the following files:

- Affix file with grammar rules- \*.aff
- Basic words file – \*.dic file

#### Adding Hunspell dictionary

1. Add your [HunspellDictionary](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.HunspellDictionary.html)’s required culture files \*.aff and \*.dic  as Resource to the application. We are going to add the Hunspell dictionary for the French culture.  
Refer to the following screenshot.  
 ![Add the Hunspell dictionary for the French culture.](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Add-the-Hunspell-dictionary-for-the-French-culture.png)
2. Create an instance of HunspellDictionary and add the basic word and grammar file path to the [HunspellDictionary.DictionaryPath](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.HunspellDictionary.html#Syncfusion_Windows_Forms_Tools_HunspellDictionary_DictionaryPath) and [HunspellDictionary.GrammarPath](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.HunspellDictionary.html#Syncfusion_Windows_Forms_Tools_HunspellDictionary_GrammarPath)  
properties and add the culture to the [HunspellDictionary.Culture](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.HunspellDictionary.html) property.
3. Add the HunspellDictionary to the [SpellCheckerAdv.Dictionaries](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_Culture) collection.
4. Set the required culture to the SpellCheckerAdv.Culture property.  
Refer to the following code example.
```csharp
//Creating a culture instance. 
CultureInfo culture = new CultureInfo("fr-FR"); 
SpellCheckerAdv SpellChecker = new SpellCheckerAdv(); 
// Adding Hunspell dictionaries in Dictionaries collection. 
SpellChecker.Dictionaries = new DictionaryCollection(); 
//Adding French culture Hunspell dictionary. 
SpellChecker.Dictionaries.Add(
 new HunspellDictionary() 
{
 Culture = culture, GrammarPath = @"\FrenchDictionary\french.aff",
 DictionaryPath = @"\FrenchDictionary\french.dic"
} 
); 
//Setting French culture for SpellChecker. 
SpellChecker.Culture = culture;
```

In a similar way, you can add and set the culture for the Ispell and OpenOffice dictionaries by referring  to this [documentation](https://help.syncfusion.com/windowsforms/spell-checker/custom-dictionary#spellcheck-using-ispell-dictionary).

## Switching languages (cultures) at runtime

You can add any number of Hunspell, Ispell, or OpenOffice dictionaries to the SpellCheckerAdv.Dictionaries collection.

You can change the spell checker’s culture at runtime by changing the SpellCheckerAdv.Culture property.

Based on the value of the SpellCheckerAdv.Culture, the set dictionary will be used for spell check. Refer to the following code.

```csharp
//Creating a culture instance. 
CultureInfo culture = new CultureInfo("fr-FR"); 
SpellCheckerAdv SpellChecker = new SpellCheckerAdv(); 
// Adding Hunspell dictionaries in Dictionaries collection. 
SpellChecker.Dictionaries = new DictionaryCollection(); 
//Add French culture Hunspell dictionary. 
SpellChecker.Dictionaries.Add(
 new HunspellDictionary() 
{ 
Culture = culture, 
GrammarPath = @"\FrenchDictionary\fr-FR.aff", 
DictionaryPath = @"\FrenchDictionary\fr-FR.dic"
} 
); 
//Add Spanish culture Hunspell dictionary. 
SpellChecker.Dictionaries.Add(
 new HunspellDictionary() 
{ 
Culture = new CultureInfo("es-ES"), 
GrammarPath = @"\SpanishDictionary\es-ES.aff", 
DictionaryPath = @"\SpanishDictionary\es-ES.dic"
} 
); 
//Add US culture Hunspell dictionary. 
SpellChecker.Dictionaries.Add( new HunspellDictionary() 
{ 
Culture = new CultureInfo("en-US"), 
GrammarPath = @"\USDictionary\en-US.aff", 
DictionaryPath = @"\USDictionary\/en-US.dic"
} 
); 
//Setting French culture for SpellChecker. 
SpellChecker.Culture = culture;
```

![SpellCheckerDialog showing suggestions for misspelled words](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Switch-culture-at-runtime.png)Here, SpellChecker.Culture is set to fr-FR . So, the dictionary for fr-FR culture will be used as the spell check dictionary.

## Get suggestions for fixing error words

Spell Checker will suggest a list of relevant words by passing the error word in these methods:

- [GetSuggestions](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_GetSuggestions_System_String_)
- [GetPhoneticWords](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_GetPhoneticWords_System_String_)
- [GetAnagrams](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_GetAnagrams_System_String_)

Refer to the following code.

```csharp
this.spellCheckerAdv1.GetSuggestions("Textboxx"); 
this.spellCheckerAdv1.GetPhoneticWords("Textboxx"); 
this.spellCheckerAdv1.GetAnagrams("Textbox");
```

## Ignore special expressions

Spell Checker gives you the option to add misspelled words from the input text to the error list. It also allows you to ignore spell checking for special expressions like EmailID, HTML tags, alphanumeric words, and more.

Refer to the following code example.

```csharp
SpellCheckerAdv checker = new SpellCheckerAdv();
checker.IgnoreEmailAddress = true;
checker.IgnoreFileNames = true;
checker.IgnoreHtmlTags = true;
checker.IgnoreUrl = true;
checker.IgnoreSpecialSymbols = true;
checker.IgnoreMixedCaseWords = true;
checker.IgnoreUpperCaseWords = true;
checker.IgnoreAlphaNumericWords = true;
```

These options are accessible at runtime through the Spell Checker Options dialog. This can be invoked by using the Options button available in the SpellChecker dialog.

Refer to the following screenshots.  
 ![Spell Checker dialog box](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Spell-Checker-dialog-box.png)  
 ![Spell Checker Options dialog box](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Spell-Checker-Options-dialog-box.png)

## Configuring VisualStyle

The Spell Checker supports the following themes:

- Default
- Metro
- Office2016Colorful
- Office2016White
- Office2016DarkGray
- Office2016Black

The following code example allows you to set the [VisualStyle](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.SpellCheckerAdv.html#Syncfusion_Windows_Forms_Tools_SpellCheckerAdv_VisualStyle) for the Spell Checker.

```csharp
this.spellCheckerAdv1.VisualStyle = Syncfusion.Windows.Forms.Tools.SpellCheckerAdvStyle.Office2016Black;
```

![Office2016Black - WinForms Spell Checker](https://www.syncfusion.com/blogs/wp-content/uploads/2020/09/Office2016Black.png)<figcaption>Office2016Black</figcaption>

You can set the visual style for different themes by referring to this [documentation](https://help.syncfusion.com/windowsforms/spell-checker/visualstyle) page.

## Conclusion

I hope you have a clear idea about the advantage of adding [WinForms Spell Checker](https://www.syncfusion.com/winforms-ui-controls/spell-checker) to a text editor control. With these features, you can dynamically check spelling for any language and culture, get suggestions, ignore special expressions, and add beautiful visual styles. So, try them out and leave your comments in the feedback section below.

For existing customers, the newest version of Essential Studio is available for download from the [License and Downloads](https://www.syncfusion.com/account/downloads) page. If you are not yet a Syncfusion customer, you can try our 30-day [free trial](https://www.syncfusion.com/downloads) to check out our available features. Also, try our samples from this [GitHub](https://github.com/syncfusion) location.

You can also contact us through our [support forum](https://www.syncfusion.com/forums), [Direct-Trac](https://www.syncfusion.com/support/directtrac/incidents), or [feedback portal](https://www.syncfusion.com/feedback/winforms). We are always happy to assist you!