Application.Exit() problems
Hello, as part of my application i have been designing for 2 months now, i use multiple form objects within the application.
After a form has been opened, to close it i used the Application.Exit method, this would close the particular form and everything would be fine.
Since isntalling the Service Pack 2 (and ive tried 3) runtimes on my device, when i open a new form inside the application, after ive done what i want to do with the form and try to close it the same way as before (i have made no code changes) it seems to close every single form that is open and terminate the entire application.
Ive searched through the changelog for SP2/3 and find no mention of a change to the way that Application.Exit() works, yet this has crippled the functionality of my program.
Has anyone got any ideas as to why this is happening? or is there another method that can be called to close the active form, as me.close doesnt work, and the Form.ActiveForm.Close method isnt supported in the compact framework.
Any help would be greatly appreciated
Best regards
Clint
Application.Exit has always worked like that: it kills your entire application.
The clean way of exiting your app however is to close the main form (through code or via user action).
If you are a few screens deep into your application, you should still design your app in a way that the user can navigate to the first (main) form and close that. Worst case scenario, you could keep a static reference to the form before passing it to Application.Run and hence have access to close it from other forms as well [not reccommended but should work if you really must].
Cheers
Daniel
Before i installed the service pack cab's on my device, any application.exit call i made from within a form, closed that form only, not the entire application (which is the functionality i wanted, and was getting) after installing the SP2/3 cab's it now kills the entire application, including all the forms that are open.
ill tell you how my application works so you can get a better understanding.
The user will navigate through a series of forms entering data which gets saved to a SQLCE database.
Due to the nature of the program, the user may open a form multiple times, hence each instance of the form needing to be terminated before it is opened again.
Is there a way of Opening a new form, and then closing THAT form only, without killing the main application page?
For example, the user will select the call they are recordnig data about, and open a new form which holds the controls for data input and a button to commit the records to the databse etc, i then need to close THAT instance of the form, and then the user will select their next call, re-opening the same data entry form, but afresh.
As i said this is puzzling as before i installed the service packs, application.exit worked perfectly, and that understanding i took from the Paul Yao book whilst i was learning vb .net compact.
Regarding the static reference to the form, that is not explicitly needed, as i wont be closing one form via another, i just now need a new way of closing the particular form i am on via a button, without affecting any other forms that are open.
Thank you for your reply, i hope i can get a little more light shed on my problem.
regards
clint
From your button click event handler:
Me.Close() 'VB
this.Close(); //C#
As an aside, if you set the MinimizeBox to true/false for your forms, that toggles the OK/X button of the form. Not sure if you are using that at the moment.
Another aside, you can handle the Closing/Closed events of a form to take last minute actions or even cancel closing the form.
Cheers
Daniel
Thanks alot,
I looked into the minimizebox property some time ago, but as this is a port of an old application to vb.net the users are already trained in using the app a particular way, so to minimise the need for re-training i decided to make it as close to the old application as possible.
Thanks for the heads up on the Closing/Closed handlers.
Thanks for your help, much appreciated!
Clint