I can't see where MsgBoxResult
came from, but this should work:
Dim MsgBoxResult As DialogResult
MsgBoxResult = MessageBox.Show( _
"Are You Sure You Want To Quit?", _
Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
Select Case MsgBoxResult
Case DialogResult.Yes
' Do nothing - let it close!
'Application.Exit()
Case DialogResult.No
e.Cancel = True
End Select
Or glue it together:
Dim MsgBoxResult As DialogResult = MessageBox.Show("Are You Sure You Want To Quit?",
Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
By calling Application.Exit you were invoking a new FormClose event before this one completed. Provided this is a MainForm, just let the application close normally.