2

Inside form I have txtbox with following event code

 private void txtCode_KeyPress(object sender, KeyPressEventArgs e)
 {
      char ch = e.KeyChar;
      if (!Char.IsDigit(ch) && ch != 8)
      {
          e.Handled = true;
          errorProvider1.SetError(txtCode, "numbers only");
      }
 }

Error icon is shown right to the txtbox with error message, how can I remove this error icon when user input is cleared or deleted or replaced with valid (digit) input?

These way it stays shown always.

4

1 回答 1

4

添加 else 语句,如

else
{
   errorProvider1.SetError(txtCode, "");
}
于 2013-07-10T12:29:21.893 回答