【发布时间】:2016-09-10 18:38:20
【问题描述】:
我目前正在开发一个带有产品维护页面的桌面应用程序,我正在寻找一种在单个消息框中显示所有验证错误的方法。
我使用下面的代码为每个验证错误显示一个消息框:(验证绑定到保存按钮)
if ((Convert.ToInt32(txtQuantity.Text)) > 20000)
{
MessageBox.Show("Maximum quantity is 20,000!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtQuantity.Focus();
return;
}
if ((Convert.ToInt32(txtQuantity.Text)) <= (Convert.ToInt32(txtCriticalLevel.Text)))
{
MessageBox.Show("Quantity is lower than Critical Level.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtQuantity.Focus();
return;
}
if (txtCriticalLevel.Text == "0")
{
MessageBox.Show("Please check for zero values!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtCriticalLevel.Focus();
return;
}
我想让用户轻松地一次了解所有错误,而不是每个显示的消息框一一了解。
提前致谢! :)
【问题讨论】:
标签: c# validation messagebox