こんにちは、Visual Studio 2010 C# で大学のプロジェクトに取り組んでいます。8 つのテキスト ボックスを持つ WinForms アプリケーションがあります。ユーザーがテキスト ボックスを空のままにしておくと、エラー アイコンがポップアップ表示され、その横にラベルが表示され、エラー メッセージが表示されます。
以下のコードを実行すると、最初の 2 つのエラー プロバイダーのみが機能します。残りは表示されません。
誰でも私を助けることができますか?
private void textBox1_Leave(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text))
{
errorProvider1.SetError(textBox1,"REQUIRED FIELD");
label12.Text = "REQUIRED FIELD";
}
else
{
errorProvider1.Dispose();
}
}
private void textBox2_Leave(object sender, EventArgs e)
{
monthCalendar1.Visible = false;
if (String.IsNullOrEmpty(textBox2.Text))
{
errorProvider2.SetError(textBox2,"REQUIRED FIELD");
label13.Text = "REQUIRED FIELD";
}
else
{
errorProvider2.Dispose();
}
}
private void textBox3_Leave(object sender, EventArgs e)
{
if (textBox3.Text=="")
{
errorProvider3.SetError(textBox3, "REQUIRED FIELD");
label14.Text = "REQUIRED FIELD";
}
else
{
errorProvider3.Dispose();
}
}
private void textBox4_Leave(object sender, EventArgs e)
{
monthCalendar1.Visible = false;
if (String.IsNullOrEmpty(textBox4.Text))
{
errorProvider4.SetError(textBox4, "REQUIRED FIELD");
label15.Text = "REQUIRED FIELD";
}
else
{
errorProvider4.SetError(textBox4, "");
}
}
private void textBox5_Leave(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox5.Text))
{
errorProvider5.SetError(textBox5, "REQUIRED FIELD");
label16.Text = "REQUIRED FIELD";
}
else
{
errorProvider5.SetError(textBox5, "");
}
}
private void textBox6_Leave(object sender, EventArgs e)
{
monthCalendar2.Visible = false;
if (String.IsNullOrEmpty(textBox6.Text))
{
errorProvider6.SetError(textBox6, "REQUIRED FIELD");
label17.Text = "REQUIRED FIELD";
}
else
{
errorProvider6.SetError(textBox6, "");
}
}