Error Provider in TextBox Control using C#

T.saravanan
Posted by T.saravanan under Windows Forms category on | Points: 40 | Views : 13107
Hi,

Here i have given a code snippet for how to set Error Provider in TextBox Leave Event in Windows Application using C#.

Private void textbox_Leave(object sender,EventArgs e)
{
if(txtbox.Text.Equals(string.Empty))
{
errProv.BlinkRate=300;
errProv.BlinkStyle=ErrorBlinkStyle.AlwaysBlink;
errProv.SetError(txtbox,"Enter Your Name");
txtbox.Focus();
}
else
{
errProv.SetError(txtbox,string.Empty);
}
}


Here txtbox --> TextBox
errProv --> Error Provider

Use this same code in any Control Validation and any Event.

Thanks :)

Comments or Responses

Login to post response