Click here to Skip to main content
11,805,604 members (63,077 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB9.0 VB VB.NET
I'm trying to allow the user to choose whether or not they really want to close the form, in case they accidentally click the X button. I have it where the application asks whether they want to close it, and when they click "Yes", it closes. But, what should I put in the "No" event handler so that it stops the form from closing?

The code that I have so far is in the Form's (Form_Closing) event.
Posted 19-Nov-10 16:12pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try setting Cancel = True in the Closing event to prevent the form from unloading.
drummerboy0511 at 19-Nov-10 22:34pm
Ahh... I'm unsure of how to do this.
Abhinav S at 20-Nov-10 2:48am
Have a look at
Dalek Dave at 20-Nov-10 4:58am
5 for that, spot on.
Abhinav S at 20-Nov-10 11:04am
Thanks DD.
drummerboy0511 at 20-Nov-10 11:13am
Ahh, okay. Thank you very much!
Abhinav S at 20-Nov-10 22:59pm
You are welcome.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi! I have the solution of this Problem

Use This Code :

Private Sub FrmMDI_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Dim Flag As Integer
    Flag = (MsgBox("Are you sure you want to exit ? ", vbInformation + vbOKCancel, "Exit"))
    If Flag = 2 Then e.Cancel = 1
End Sub

And Your Problem is Solved.
Thank you. Smile | :)
drummerboy0511 at 20-Nov-10 11:12am
Thank you very much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 3,265
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 20 Nov 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100