I usually just add a Property to the form to indicate how the form is being closed - e.g. from within Code or via a User action. Then only set cancel based on that property or if the "close" is coming from your code, allow it through
As each form is a class you can add a property to it - here are some examples of how
https://www.dotnetperls.com/property-vbnet[
^]
Private Sub CloseToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseToolStripMenuItem.Click
If Ending_Session_Quest.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
This.AllowClose = True
Else
This.AllowClose= False
End If
End Sub
Then in your Form closing event so something like this
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not This.AllowClose Then
e.Cancel = False
End If
End Sub