Why Should You Integrate Syncfusion WinForms Spell Checker into Your Text Editor? | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (199)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (63)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (892)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (62)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (37)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (497)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (379)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (319)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Why Should You Integrate Syncfusion WinForms SpellChecker into Your Text Editor

Why Should You Integrate Syncfusion WinForms Spell Checker into Your Text Editor?

Syncfusion WinForms 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:

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.
    using Syncfusion.Windows.Forms.Tools;
    
  2. Create the SpellCheckerAdv control instance.
    SpellCheckerAdv spellCheckerAdv1 = new SpellCheckerAdv();
    

Step 3: Configure the SpellCheckerAdv in TextBox.

  1. In the WinForms project, create a class implementing the ISpellCheckerAdvEditorTools interface.
    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.
    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

  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 method.
    TextBoxSpellEditor TextEditor = new TextBoxSpellEditor(this.richTextBox1);
    this.spellCheckerAdv1.PerformSpellCheckForControl(TextEditor);
    
  4. Finally, trigger the SpellCheckerAdv through the Click event of a button.
    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
Text editor control with WinForms Spell Checker

Load your own dictionary for any language

You can add your own dictionary to the 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’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.
  2. Create an instance of HunspellDictionary and add the basic word and grammar file path to the HunspellDictionary.DictionaryPath and HunspellDictionary.GrammarPath
    properties and add the culture to the HunspellDictionary.Culture property.
  3. Add the HunspellDictionary to the SpellCheckerAdv.Dictionaries collection.
  4. Set the required culture to the SpellCheckerAdv.Culture property.
    Refer to the following code example.

    //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.

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.

//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 wordsHere, 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:

Refer to the following code.

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.

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
Spell Checker Options dialog box

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 for the Spell Checker.

this.spellCheckerAdv1.VisualStyle = Syncfusion.Windows.Forms.Tools.SpellCheckerAdvStyle.Office2016Black;
Office2016Black - WinForms Spell Checker
Office2016Black

You can set the visual style for different themes by referring to this documentation page.

Conclusion

I hope you have a clear idea about the advantage of adding WinForms 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 page. If you are not yet a Syncfusion customer, you can try our 30-day free trial to check out our available features. Also, try our samples from this GitHub location.

You can also contact us through our support forumDirect-Trac, or feedback portal. We are always happy to assist you!

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed