如何停止 TypeValidationCompleted 事件?

发布于 2024-10-05 06:45:28 字数 396 浏览 0 评论 0原文


我已经添加了一个日期掩码文本框。
现在在掩码文本框中 TypeValidationCompleted 代码...

If (Not e.IsValidInput) Then
                MsgBox("The data you supplied must be a valid date.", MsgBoxStyle.Critical, "Date Error")
                tdatemask.Text = ""
                tdatemask.Focus()
            End If

现在,当我尝试通过按表单的关闭按钮退出表单时,也会发生此事件。
现在我的问题是“当我们尝试退出表单时如何停止此事件?”



i had included one masktext box for date.

now in mask text boxes TypeValidationCompleted code...

If (Not e.IsValidInput) Then
                MsgBox("The data you supplied must be a valid date.", MsgBoxStyle.Critical, "Date Error")
                tdatemask.Text = ""
                tdatemask.Focus()
            End If

now when i try to exit the form by pressing close button of form then also this event is occurring.
now my question is "how to stop this event while we try to exit the form?"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装不在乎 2024-10-12 06:45:28

您可以设置一个标志,然后当validationcompleted事件开始时您检查该标志,如果设置为true(意味着表单正在关闭)您可以让它忽略检查。

EX: _formClosing 将是一个全局布尔值,在表单关闭事件期间设置为 true。

If (Not e.IsValidInput) and (Not _formClosing) Then
            MsgBox("The data you supplied must be a valid date.", MsgBoxStyle.Critical, "Date Error")
            tdatemask.Text = ""
            tdatemask.Focus()
        End If

You can set a flag and then when the validationcompleted event kicks off you check for the flag, if set to true (meaning the form is closing) you can have it ignore the check.

EX: _formClosing would be a global boolean that is set to true during form closing event.

If (Not e.IsValidInput) and (Not _formClosing) Then
            MsgBox("The data you supplied must be a valid date.", MsgBoxStyle.Critical, "Date Error")
            tdatemask.Text = ""
            tdatemask.Focus()
        End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文