RichTextBox: Using TX Spell .NET with Multiple RichTextBox Instances

Integrating TX Spell .NET for Windows Forms with TX Text Control requires no code - it can be easily connected using the Visual Studio designer. To increase performance, the spelling dialog is opened by TX Text Control and not TX Spell .NET. The dialog that is opened by TX Text Control is pre-configured and can't be customized. Alternatively, you can open a fully customizable SpellCheckDialog from TX Spell .NET.

The source code is contained in the following directories:

  • %USERPROFILE%\My Documents\TX Spell 7.0.NET for Windows Forms\Samples\WinForms\CSharp\RichTextBox\Multiple controls
  • %USERPROFILE%\My Documents\TX Spell 7.0.NET for Windows Forms\Samples\WinForms\VB.NET\RichTextBox\Multiple controls

A high-performance spell checker requires a well-considered concept to work with multiple controls on a form in the same application. A single TX Spell .NET instance can be used with multiple instances of the RichTextBox. It is not necessary to have one instance of the spell checker for each instance of the RichTextBox, any other control of the .NET Framework or third-party control. This dramatically reduces the required memory and speeds up the spell checking process.

The concept of using multiple instances of the RichTextBox with the same instance of TX Spell .NET is very straightforward. It is not neccessary to switch manually between the controls. When text is changed in one of the RichTextBoxes, the TXTextControl.Proofing.TXSpellChecker.Check method is called and the misspelled words are colorized:

foreach (TXTextControl.Proofing.IncorrectWord incorrectWord in txSpellChecker1.IncorrectWords)
    if (incorrectWord.Start <= textPosition && textPosition <= incorrectWord.Start + incorrectWord.Length)
        richTextBox.Select(incorrectWord.Start, incorrectWord.Length);
        richTextBox.SelectionColor = System.Drawing.Color.Red;
        richTextBox.SelectionLength = 0;
        richTextBox.SelectionStart = lastTextPosition;
For Each incorrectWord As TXTextControl.Proofing.IncorrectWord In txSpellChecker1.IncorrectWords
    If incorrectWord.Start <= textPosition AndAlso textPosition <= incorrectWord.Start + incorrectWord.Length Then
        richTextBox.[Select](incorrectWord.Start, incorrectWord.Length)
        richTextBox.SelectionColor = System.Drawing.Color.Red
        richTextBox.SelectionLength = 0
        richTextBox.SelectionStart = lastTextPosition
    End If

Start the application and type text into each of the RichTextBoxes. Misspelled words are colorized in red automatically.