如何清除c#选项卡页面中的错误图标?
在过去的5个小时里,我一直在研究并试图清除出现在每个文本框右侧的必填字段(城市、州、国家、经度和纬度)中的错误图标,如果用户没有在其中输入内容 这一切都很好,除了创建按钮显示条目创建消息后,我单击确定,字段重置和全部,但所有5个错误图标都显示在它们旁边 如何在单击消息ok后重新加载选项卡页面,以便在消息确认后停止显示这些错误图标 只有当我关闭并重新加载整个表单时,图标才不在那里。我不想为了让他们一开始就不出现而不断重做 下面是与我试图完成的任务相关的部分代码:如何清除c#选项卡页面中的错误图标?,c#,winforms,C#,Winforms,在过去的5个小时里,我一直在研究并试图清除出现在每个文本框右侧的必填字段(城市、州、国家、经度和纬度)中的错误图标,如果用户没有在其中输入内容 这一切都很好,除了创建按钮显示条目创建消息后,我单击确定,字段重置和全部,但所有5个错误图标都显示在它们旁边 如何在单击消息ok后重新加载选项卡页面,以便在消息确认后停止显示这些错误图标 只有当我关闭并重新加载整个表单时,图标才不在那里。我不想为了让他们一开始就不出现而不断重做 下面是与我试图完成的任务相关的部分代码: private void crea
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();
}
}
winforms/wpf?添加正确的标记plz。@AnjumSKhan yup forms…添加了标记使用一个ErrorProvider,它可以在任何控件上显示警告。使用SetError(控件“”)隐藏警告。然后,它的Clear()方法会删除所有警告。Hans,我最初尝试过alrdy,但没有成功