Group 3: TextBox Validation

The third group box consists only of a TextBox and another Button. Typing some text into the TextBox and click on OK.

The result of this sample is very similar to the first group, but it uses the Validating and Validated events of the TextBox. The Validating event is fired everytime when the TextBox looses the focus. On this event, TX Spell .NET is used to check the text.

[C#]
private void tbDemo3_Validating(object sender, CancelEventArgs e)
{
	txSpellChecker1.Check(tbDemo3.Text);

	if (txSpellChecker1.IncorrectWords.Count > 0)
	{
		label4.Text = "Misspelled.";
		label4.ForeColor = Color.Red;
		e.Cancel = true;
	}
}
[Visual Basic]
Private Sub tbDemo3_Validating(sender As Object, e As CancelEventArgs)
	txSpellChecker1.Check(tbDemo3.Text)

	If txSpellChecker1.IncorrectWords.Count > 0 Then
		label4.Text = "Misspelled."
		label4.ForeColor = Color.Red
		e.Cancel = True
	End If
End Sub

If the text is misspelled, the following Validated event is canceled. If not, the Validated event will be fired.