안녕하세요 저는 Visual Studio 2010 C#에서 대학 프로젝트를 진행하고 있습니다. 8 개의 텍스트 상자가있는 WinForms 응용 프로그램이 있습니다. 사용자가 텍스트 상자를 비워 둘 때마다 오류 아이콘이 표시되고 오류 아이콘을 표시하는 레이블이 표시되어야합니다.모든 errorproviders가 제대로 작동하지 않습니다.
아래 코드를 실행하면 처음 두 오류 공급자 만 작동합니다. 나머지는 나타나지 않습니다.
아무도 도와 줄 수 있습니까?
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, "");
}
}
해결 방법을 시도했지만 나에게 도움이되지 못했습니다. 대체 솔루션을 원하십니까 ?? ... 노력 neway 감사합니다 – Brian
좀 더 구체적으로 말하십시오. 무슨 일을 했지? 컴파일 오류? 런타임 에러? 원하는 효과가 아닙니까? 모든 errorprovider 컨트롤을 하나로 변경하고 모두 이름을 변경 했습니까? 나는 단지 하나의 이름을 바꾸는 것을 보여 줬다. – okrumnow
didnt는 원하는 효과를 얻는다. 모든 errorproviders에 string.empty 속성을 별도로 사용했습니다. – Brian