Click here to Skip to main content
11,934,389 members (71,537 online)
Rate this:
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 17: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 19-Nov-10 22:34pm
Ahh... I'm unsure of how to do this.
Abhinav S 20-Nov-10 2:48am
Have a look at
Dalek Dave 20-Nov-10 4:58am
5 for that, spot on.
Abhinav S 20-Nov-10 11:04am
Thanks DD.
drummerboy0511 20-Nov-10 11:13am
Ahh, okay. Thank you very much!
Abhinav S 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.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