I am trying to validate textboxes for empty values. If the textbox is empty and loses focus, an error has to show and the textbox has to receive focus again.
Reading about this I came across the Validating event, which can be cancelled through e.Cancel. However when I try to do this, I get an error message.
My code:
private void CheckInput(CancelEventArgs e, TextBox tb)
{
ErrorProvider error = new ErrorProvider();
if (!string.IsNullOrEmpty(tb.Text))
{
error.SetError(tb, "*");
e.Cancel = true;
}
else
{
error.SetError(tb, "");
}
}
private void tbTitel_Validated(object sender, CancelEventArgs e)
{
CheckInput(e, tbTitel);
}
And the error I get is the following:
Error 1 No overload for 'tbTitel_Validated' matches delegate 'System.EventHandler'
How can I fix this?