|
-
Apr 18th, 2013, 08:08 PM
#1
Thread Starter
Lively Member
Program Wont Close
I have a program starting with FormA, and opens to Forms B, C, D, E, etc... When I close forms B, C, D, E, it doesn't close the program. So I added this tidbit of code:
Code:
Private Sub AnalysisMain_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
Me.Close()
End Sub
This just causes the program to freeze. 
Im sure theres a simple solution here 
Ryan
-
Apr 18th, 2013, 08:13 PM
#2
Re: Program Wont Close
Well something's obviously causing the program not to close. What you should do is first take the Me.Close out of your FormClosing. Next, set up a breakpoint at your form closing just to make sure your form is indeed trying to close. Some info that may be useful: A)How are you closing the program?(Clicking the red x or in code?) B)What do you expect to happen when you close a form?(Just close that single form or the whole application?) C)Is there perhaps some long running process going on that we don't know about?
-
Apr 18th, 2013, 08:19 PM
#3
Re: Program Wont Close
you have 5 forms. when exactly should the app. exit?
when all forms are closed, or something different?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 18th, 2013, 08:21 PM
#4
Thread Starter
Lively Member
Re: Program Wont Close
A) Pressing red X
B) Close the whole application
C) Not on this application, I have one on another form, but it isnt running in this case. Ill tackle that problem when I get there
-
Apr 18th, 2013, 08:21 PM
#5
Re: Program Wont Close
Code:
Private Sub AnalysisMain_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
Application.Exit
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2013, 09:32 AM
#6
Re: Program Wont Close
 Originally Posted by rpmaurer
I have a program starting with FormA, and opens to Forms B, C, D, E, etc... When I close forms B, C, D, E, it doesn't close the program. So I added this tidbit of code:
Code:
Private Sub AnalysisMain_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
Me.Close()
End Sub
This just causes the program to freeze.
Im sure theres a simple solution here
Ryan
The very first thing I see is that you're calling the form's Close method in the FormClosing event, the funny thing about this is that the only way the FormClosing event fires is if the Close method is called, when your form is already closing there's no need to call its close method.
That being said, I *think* I understand what you're wanting to do, so correct me if I'm wrong.
I think you have two forms open: the "base" form (the one that when closed will end the program) and a secondary form, of which you want to end the program if this form is closed, correct?
If the above is correct, then this should work nicely for you:
vb Code:
Public Class Form1 Private WithEvents frm2 As New Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click frm2.Show(Me) End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If frm2 IsNot Nothing Then frm2.Dispose() End If End Sub Private Sub Frm2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles frm2.FormClosed Me.Close() End Sub End Class
 Originally Posted by .paul.
Code:
Private Sub AnalysisMain_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
Application.Exit
End Sub
You should avoid calling 'End' and 'Application.Exit' in applications as that causes a hard-stop of your app. None of the Closing and cleanup events are fired and it doesn't allow your apps forms to clean up the objects on them (fonts, labels, textboxes, things in the form's dispose event).
 Originally Posted by MSDN
CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.
Last edited by JuggaloBrotha; Apr 19th, 2013 at 10:30 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|