RichTextBox: Using a Custom Spell Check ContextMenu

When TX Spell .NET is connected to a TextControl through the SpellChecker property, TextControl provides a pre-defined spell check context menu that can be used to replace the misspelled word, open the SpellCheckDialog or to open the options user dialog. But sometimes, it is required to create a customizable context menu or to include the spell check menu items into an existing menu.

The source code is contained in the following directories:

  • Samples\WPF\CSharp\RichTextBox\Context menu strip
  • Samples\WPF\VB.NET\RichTextBox\Context menu strip

TX Spell .NET provides the GetMenuItems method that returns ready-to-use menu items that can be inserted into an existing ContextMenuStrip. The method accepts a misspelled word, the text of the RichTextBox instance and the maximum number of returned suggestions.

TXTextControl.WPF.Proofing.MenuItem[] items = txSpellChecker1.GetMenuItems(
    currentIncorrectWord,
    new TextRange(richTextBox1.Document.ContentStart,
    richTextBox1.Document.ContentEnd).Text, 5);
Dim items As TXTextControl.WPF.Proofing.MenuItem() = txSpellChecker1.GetMenuItems( _
    currentIncorrectWord, _
    New TextRange(richTextBox1.Document.ContentStart, _
    richTextBox1.Document.ContentEnd).Text, 5)

TX Spell .NET provides different MenuItemTypes for different purposes such as deleting, ignoring or to add a word to a user dictionary.

Start the sample application and right-click on a misspelled word. You can replace the misspelled word with a correct suggestion, you can ignore it or you can add it to the user dictionary.

Image