我想检查 btn 单击时是否有任何文本框为空,然后在其一侧显示相应的 SetError msg
bool isIncomplete = false;
foreach (Control control in this.Controls)
{
if (control is TextBox)
{
TextBox tb = control as TextBox;
if (string.IsNullOrWhiteSpace(tb.Text))
{
isIncomplete = true;
break;
}
}
} // I think this.controls does not work properly..
if (isIncomplete)
{
errorProvider1.SetError(firstname_txtbox, "First Name is required.");
errorProvider2.SetError(lastname_txtbox, "Last Name is required.");
MessageBox.Show("Please fill all the textbox correctly!");
return;
} else if(firstname_txtbox.Text.Length < 2)
{
errorProvider1.SetError(firstname_txtbox, "First Name need to be at least 2 characters"); //this error message does appear through...
}else if() { etc..
单击时不会显示 errorProvider 消息。我的文本框在面板内...