How to use Error Provider Control in Windows Forms and C#
How to use Error Provider Control in Windows Forms and C# TextBox 1 Validating
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
private bool CheckName() { bool status = true; if (textBox1.Text=="") { errorProvider1.SetError(textBox1,"Please Enter Your Name"); status = false; } else { errorProvider1.SetError(textBox1,""); } return status; } |
TextBox 2 Validating
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
private bool CheckAge() { bool status = true; if (textBox2.Text=="") { errorProvider1.SetError(textBox2,"Please Enter Your Age"); status = false; } else { errorProvider1.SetError(textBox2,""); try { int checkage = int.Parse(textBox2.Text); errorProvider1.SetError(textBox2, ""); if (checkage<18) { errorProvider1.SetError(textBox2, "your age must be 18 year old"); status = false; } else { errorProvider1.SetError(textBox2, ""); } } catch (Exception ex) { errorProvider1.SetError(textBox2, "Please enter your age as number"); status = false; } } return status; } |
When
Read More