The predicate of your if-Statement has a constant value, namely
Windows.Forms.DialogResult.Yes
and that apparently counts as
True
. So the first branch gets always executed no matter what. In other words, you don't actually check for the result of the
MessageBox.Show(..)
-Method. You need to capture its return value and compare that to
Windows.Forms.DialogResult.Yes
:
Dim result As Windows.Forms.DialogResult
result = MessageBox.Show("Do you really want to leave?", "Exiting.", MessageBoxButtons.YesNo)
If result = Windows.Forms.DialogResult.Yes Then
End
Else
Exit Sub
End If