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:

Using a customizable 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 Proofing.TXSpellChecker.Check method must be called before the dialog is opened:

[C#]
txSpellChecker1.Check(richTextBox1.Text);
txSpellChecker1.SpellCheckDialog.Show();
[Visual Basic]
txSpellChecker1.Check(richTextBox1.Text)
txSpellChecker1.SpellCheckDialog.Show()

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

[C#]
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;
	}
}
[Visual Basic]
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.