当用户点击“确定”按钮时,我会将其输入验证为:
private void btnOk_Click(object sender, EventArgs e)
{
myTxtField_Validated(this, e);
myTxtField2_Validated(this, e);
CustomObject obj = new CustomObject .....
}
在验证内部,我使用错误提供程序通知用户字段中的输入必须符合某些条件。
如果验证中断,我如何以静默方式中断此部分CustomObject obj = new CustomObject ....
的执行。它可以按预期使用现有的验证代码。
答案 0 :(得分:1)
使用私有布尔成员可以轻松实现这一点,并按照以下方式实现:
private bool _validatedTextFields;
private void btnOk_Click(object sender, EventArgs e)
{
myTxtField_Validated(this, e);
myTxtField2_Validated(this, e);
if (_validatedTextFields)
{
CustomObject obj = new CustomObject .....
}
}
private void myTxtField_Validated(object sender, EventArgs e)
{
//your validation...
_validatedTextFields = true //only set your member to true if it has been validated.
}
private void myTxtField2_Validated(object sender, EventArgs e)
{
//your validation...
_validatedTextFields = true //only set your member to true if it has been validated.
}