Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB9.0 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 17:12pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try setting Cancel = True in the Closing event to prevent the form from unloading.
  Permalink  
v3
Comments
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 http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx.
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
good
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
End Sub
 
And Your Problem is Solved.
Thank you. Smile | :)
  Permalink  
Comments
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 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 20 Nov 2010
Copyright © CodeProject, 1999-2014
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