Application exit dialog

Pierre

Member
Joined
Jan 4, 2003
Messages
5
Location
New Jersey
I am struggling with the following logic that lies behind an exit button for a Windows application, which purpose is to ask the user to confirm that he wants to exit the application before actually executing the exit:


Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Exit the application
MessageBox.Show("Are you sure that you want to exit the application?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
If DialogResult.Cancel Then
MsgBox("Be more careful next time!")
ElseIf DialogResult.OK Then
Application.Exit()
End If
End Sub


Indeed, it appears that the ElseIf statement never gets executed.

Can somebody give me some hints as to where the problem is?
 
you need the If Statement built into your messagebox line , eg:
Code:
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

 Exit the application
If MessageBox.Show("Are you sure that you want to exit the application?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) = DialogResult.Cancel Then
    MessageBox.Show("Be more careful next time!")
Else
    Application.Exit()
End If
End Sub
 
Back
Top