RichTextBox: Using a Customizable SpellCheckDialog

TX Spell .NET enjoys a deep integration within the main word processing component. Integrating TX Spell .NET for Windows Forms into 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. But TX Spell .NET can be used with all kind of .NET Framework or third-party controls. This sample shows how to use TX Spell .NET with the .NET RichTextBox and customizable SpellCheckDialog.

The source code is contained in the following directories:

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

Principally, the integrated SpellCheckDialog of TX Spell .NET can be used with all types of input controls. If used in combination with TX Text Control, the handling is completely automated and no additional code is required. In order to use TX Spell .NET with any other control, the TXSpellChecker.Check Method method must be called before the dialog is opened:

txSpellChecker1.Check(richTextBox1.Text);
txSpellChecker1.SpellCheckDialog.Show();
txSpellChecker1.Check(richTextBox1.Text)
txSpellChecker1.SpellCheckDialog.Show()

The dialog is automatically opened with the text of the RichTextBox. In the Proofing.TXSpellChecker.IncorrectWordChanging Event event, the misspelled word must be replaced in the connected control:

private void txSpellChecker1_IncorrectWordChanging(object sender,
    TXTextControl.Proofing.IncorrectWordChangingEventArgs e)
{
    if (e.Type == TXTextControl.Proofing.TXSpell.ChangeType.Replace)
    {
        richTextBox1.SelectedText = e.CorrectedWord;
        return;
    }
    if (e.Type == TXTextControl.Proofing.TXSpell.ChangeType.Delete)
    {
        richTextBox1.Select(e.IncorrectWord.Start, e.IncorrectWord.Length);
        richTextBox1.SelectedText = "";
        return;
    }
}
Private Sub txSpellChecker1_IncorrectWordChanging(sender As Object, _
    e As TXTextControl.Proofing.IncorrectWordChangingEventArgs)
    If e.Type = TXTextControl.Proofing.TXSpell.ChangeType.Replace Then
        richTextBox1.SelectedText = e.CorrectedWord
        Return
    End If
    If e.Type = TXTextControl.Proofing.TXSpell.ChangeType.Delete Then
        richTextBox1.[Select](e.IncorrectWord.Start, e.IncorrectWord.Length)
        richTextBox1.SelectedText = ""
        Return
    End If
End Sub

Start the sample application and click on Spell Check Dialog to start the checking process. The corrected words are replaced in the connected RichTextBox through the attached IncorrectWordChanging event.

Image