Prompt User Before Application.Exit

C

Chris Cairns

I have a MDI Application and would like to prompt the user before exit. I
placed the following in the FormClosing event. It appears to work properly,
however when a user answers no to the question it causes the application to
flash and deactivate. I was able to activate it again but it looks sort of
stupid to have the application flash when it should simply return the user
to the app.

Any ideas around this? I know I can do it easliy with exit on the main menu
but the problem still exists when the user presses the X in the upper corner
thus causing the application.exit.

'Check to see if the user want's to exit before closing the menu.
If MessageBox.Show("Are you sure you want to exit?", "Exit?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) =
Windows.Forms.DialogResult.No Then
e.Cancel = True
Me.ParentForm.Activate()
End If
 
I

Izzy

Put this and only this in your form closing event.

If MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo) =
MsgBoxResult.No Then e.Cancel = True

Izzy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top