编写此验证错误代码的简短方法是什么?

时间:2013-09-12 08:34:00

标签: c# winforms

我会问别的地方。谢谢所有回复!

1 个答案:

答案 0 :(得分:2)

可能是这个

public class ControlValidationInfo
{
    public Control Control { get; set; }
    public string EmptyTextErrorMessage { get; set; }
}

ControlValidationInfo[] infos = new []{ new ControlValidationInfo{ Control = txtSrcUserID, EmptyTextErrorMessage  = "Please enter Source User_ID"}}; // add all in this array

foreach(var info in infos)
{
    if(String.IsNullOrEmpty(info.Control.Text))
    {
        errorProvider1.SetError(info.Control , info.EmptyTextErrorMessage);
        return; 
    }
}