In MSDN I found CloseReason.UserClosing
to know that the user had decided to close the form
but I guess it is the same for both clicking the X button or clickin
I agree with the DialogResult
-Solution as the more straight forward one.
In VB.NET however, typecast is required to get the CloseReason
-Property
Private Sub MyForm_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
Dim eCast As System.Windows.Forms.FormClosingEventArgs
eCast = TryCast(e, System.Windows.Forms.FormClosingEventArgs)
If eCast.CloseReason = Windows.Forms.CloseReason.None Then
MsgBox("Button Pressed")
Else
MsgBox("ALT+F4 or [x] or other reason")
End If
End Sub