如果用户没有输入内容,我一直在研究并尝试在过去5个小时内清除每个文本框右侧所需的字段(城市,州,国家,经度和纬度)中的错误图标在他们中间。
除了事实上创建按钮显示条目创建消息之后,它一切都很好,我单击确定,字段重置和所有,但所有5个错误图标出现在它们旁边。
如何在单击消息ok后将标签页重新加载,以便在消息确认后这些错误图标停止显示?
只有当我关闭并重新加载整个表单时,图标才不存在。我不想继续重做,因为他们最初不会出现!
这是与我正在努力完成的代码相关的代码的一部分:
private void createEntryButton_Click(object sender, EventArgs e)
{
/*//if required boxes are left empty, reveal error
if (String.IsNullOrEmpty(createCityTextBox.Text) && String.IsNullOrEmpty(createStateTextBox.Text) && String.IsNullOrEmpty(createCountryTextBox.Text) && String.IsNullOrEmpty(createLongitudeTextBox.Text) && String.IsNullOrEmpty(createLatitudeTextBox.Text))
{
cityError.SetError(createCityTextBox, "City field is empty!");
stateError.SetError(createStateTextBox, "State field is empty!");
countryError.SetError(createCountryTextBox, "Country field is empty!");
longitudeError.SetError(createLongitudeTextBox, "Longitude field is empty!");
latitudeError.SetError(createLatitudeTextBox, "Latitude field is empty!");
}
*/
if (!String.IsNullOrEmpty(createCityTextBox.Text) && !String.IsNullOrEmpty(createStateTextBox.Text) && !String.IsNullOrEmpty(createCountryTextBox.Text) && !String.IsNullOrEmpty(createLongitudeTextBox.Text) && !String.IsNullOrEmpty(createLatitudeTextBox.Text))
{
//cityError.Clear();
//stateError.Clear();
//countryError.Clear();
//longitudeError.Clear();
//latitudeError.Clear();
MessageBox.Show("New entry created!");
//resetting the fields
foreach (Control item in createEntryTab.Controls)
{
if (item is TextBox)
{
item.Text = "";
}
}//end foreach
}
if (String.IsNullOrEmpty(createCityTextBox.Text))
{
cityError.SetError(createCityTextBox, "City field is empty!");
}
else
{
cityError.Clear();
}
if (String.IsNullOrEmpty(createStateTextBox.Text))
{
stateError.SetError(createStateTextBox, "State field is empty!");
}
else
{
stateError.Clear();
}
if (String.IsNullOrEmpty(createCountryTextBox.Text))
{
countryError.SetError(createCountryTextBox, "Country field is empty!");
}
else
{
countryError.Clear();
}
if (String.IsNullOrEmpty(createLongitudeTextBox.Text))
{
longitudeError.SetError(createLongitudeTextBox, "Longitude field is empty!");
}
else
{
longitudeError.Clear();
}
if (String.IsNullOrEmpty(createLatitudeTextBox.Text))
{
latitudeError.SetError(createLatitudeTextBox, "Latitude field is empty!");
}
else
{
latitudeError.Clear();
}
}