在Windows窗体C#中验证多个文本框
问题描述:
我想在Windows窗体中验证10个文本框,当我单击按钮时,所有文本框都应该有一个单独的错误消息。
如何使用errorprovider。请帮助...
I want to validate 10 Textbox in Windows form, When i click button there should be an individual error message for all the textbox which is empty.
How i can use the errorprovider for this. Please Help...
答
if(TextBox1.Text =|| TextBox2.Text =)
{
if(TextBox1.Text =)
{
errorProvider1.SetError(TextBox1,在这里输入值);
}
if(TextBox2.Text ="")
{
errorProvider1.SetError(TextBox2," Enter Value)这里);
}
}
其他
{
errorProvider1.SetError(TextBox1,null);
errorProvider1.SetError(TextBox2,null);
}
if (TextBox1.Text="" || TextBox2.Text="")
{
if(TextBox1.Text="")
{
errorProvider1.SetError(TextBox1,"Enter Value Here");
}
if(TextBox2.Text="")
{
errorProvider1.SetError(TextBox2,"Enter Value Here");
}
}
else
{
errorProvider1.SetError(TextBox1,null);
errorProvider1.SetError(TextBox2,null);
}