エラー プロバイダーをテキスト ボックスに適用しようとしていますが、
ユーザーは 25 文字を超えて入力することはできません テキストボックスを空白のままにすることはできません
private void txtNameandSurn_TextChanged(object sender, EventArgs e)
{
txtNameandSurn.MaxLength = 25;
if (txtNameandSurn.Text == "")
{
txtNameandSurn.BackColor = Color.White;
errorProvider1.SetError(txtNameandSurn, "Cannot be blank!");
}
else
{
txtNameandSurn.BackColor = Color.Red;
errorProvider1.SetError(txtNameandSurn, "");
}
if (txtNameandSurn.Text.Length >= txtNameandSurn.MaxLength)
{
errorProvider1.SetError(txtNameandSurn, "Cannot input more than 25 characters!");
}
else if (txtNameandSurn.Text.Length < txtNameandSurn.MaxLength)
{
errorProvider1.SetError(txtNameandSurn, "");
}
}
私が抱えている問題は文字入力に関するもので、エラープロバイダーが表示されますが、別のキーを押すとエラープロバイダーのアイコンが消えますが、文字は入力されません。エラー プロバイダ アイコンを表示し続けるにはどうすればよいですか?