任何人都可以帮助避免这种情况吗?
在事件处理程序中,我需要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关闭后,事件再次被触发
答案 0 :(得分:0)
快速思考是尝试使用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,因此在窗体关闭时代码将不会执行:)
答案 1 :(得分:0)
解决了改变:
Handles txObjName.Leave
通过
Handles txObjName.LostFocus
谢谢大家