BP Forums
How to exit sub of form1 using form2? - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+---- Thread: How to exit sub of form1 using form2? (/showthread.php?tid=535)



How to exit sub of form1 using form2? - Himansh - 05-21-2012

Hi everybody
I have created a software and have added a form2 to it
In form1_closing event i have added the code
form2.showdialog
In form 2 i have added a button "Cancel"
I want that when the user press this cancel button then it exits the form_closing sub which prevents the software from Closing

Can anybody tell me How to Do it

Thanks in Advance!!!!


Re: How to exit sub of form1 using form2? - brandonio21 - 05-21-2012

So what you want to do is make it so when you press cancel on form2, form1 stops closing?


Re: How to exit sub of form1 using form2? - Himansh - 05-22-2012

Yes ,You are Right!!


Re: How to exit sub of form1 using form2? - brandonio21 - 05-23-2012

Hm. Why do you want to do this? It seems really strange.


Re: How to exit sub of form1 using form2? - Himansh - 06-08-2012

Actually i am creating a software like notepad
WHen you press the X button in Microsoft notepad you will see a form with a cancel button and when you press it the notepad stops closing

Thats why i want to know how to do it


Re: How to exit sub of form1 using form2? - brandonio21 - 06-08-2012

Well, you just need to pop something like this into your code!!

Code:
Public Sub GetUserPermission(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Dim response As DialogResult
        response = MessageBox.Show("Do you really want to close?", "Really?", MessageBoxButtons.YesNoCancel) 'Show the message box
        If Not (response = Windows.Forms.DialogResult.Yes) Then
            'The user does not wish to close the form! Bail! Bail!!
            e.Cancel = True
        End If
    End Sub