任何人都可以帮助避免这种情况吗?
在事件处理程序中,我需要Cal表格,但是在卸载表格后,该事件再次发射。
Private Sub MyHandler(sender As System.Object, e As System.EventArgs) Handles txObjName.Leave
Dim MyVar As Integer = SomeValue
dim myForm as SomeForm
MyForm.ShowDialog()
关闭myform后,该事件再次触发
快速思考是尝试使用FormClosing
事件。
因此您的代码看起来像这样:
Private _Closing as boolean = False
Private Sub MyHandler(sender As System.Object, e As System.EventArgs) Handles txObjName.Leave
If Not _Closing Then
Dim MyVar As Integer = SomeValue
Dim myForm as SomeForm
MyForm.ShowDialog()
End If
End Sub
Private Sub FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
_Closing = True
End Sub
您使用FormClosing
事件将布尔 _Closing
切换到true,因此当闭合表单时,代码不会执行:)
解决的变化:
Handles txObjName.Leave
Handles txObjName.LostFocus
谢谢大家