u can use control validating event with errorprovider
example
here i have given an example to validate a textbox which accepts only integer the validate message is displayed on error provider
her is the code
private void textBox1_Validating(object sender, CancelEventArgs e)
{
try
{
int a = int.Parse(textBox1.Text);
}
catch
{
errorProvider1.SetError(textBox1, "Enter numbers only");
}
}
so here i have written the code in textBox1_Validating event
Hope this may help u