项目场景:
问题描述:
提示:
winform项目,新增弹窗里给某个TextBox添加了Leave事件验证数据准确性。但是如果TextBox数据验证不通过时需要点击窗体关闭按钮时。会先触发TextBox的Leave事件。导致窗体Close事件无法被触发。
原因分析:
点击关闭时 按钮获得焦点>TextBox失焦>按钮Click解决方案:
在TextBox Leave事件中验证按钮是否Focused。 private void txtMobile_Leave(object sender, EventArgs e)
{
if (!btnCancel.Focused)
{
getCustInfo(txtMobile.Text.Trim());
}
}