1private void textBox2_Validating(object sender, CancelEventArgs e)
2 {
3 if (textBox2.TextLength>0 && (textBox2.TextLength!=5))
4 {
5 errorProvider1.SetIconAlignment((Control)sender,ErrorIconAlignment.MiddleRight);
6 errorProvider1.SetError((Control)sender,"TextLength>0 && TextLength!=5");
7 e.Cancel=true;
8 }
9 else
10 {
11 errorProvider1.SetError((Control)sender,"");
12 }
13 }
2 {
3 if (textBox2.TextLength>0 && (textBox2.TextLength!=5))
4 {
5 errorProvider1.SetIconAlignment((Control)sender,ErrorIconAlignment.MiddleRight);
6 errorProvider1.SetError((Control)sender,"TextLength>0 && TextLength!=5");
7 e.Cancel=true;
8 }
9 else
10 {
11 errorProvider1.SetError((Control)sender,"");
12 }
13 }