我想在用户尝试关闭应用程序时检查是否满足某个条件。如果符合条件,则应用程序可以关闭,否则无法关闭。我尝试将代码FormClosing事件放入,但是当我按下ok时,无论条件如何,它都会关闭应用程序。
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim statusschimb As String = functiicomune.statusschimb()
If statusschimb <> "Inchis" Then
MsgBox("Schimbul nu este inchis! Va rugam inchideti schimbul!" & vbNewLine & "Instrumente --> Inchide schimb", MsgBoxStyle.Exclamation, "Atentie")
If DialogResult = DialogResult.Yes Then
e.Cancel = True
End If
End If
End Sub