Hey
I have an application that uses multiple forms, and I encountered a problem when closing one of the forms. This is the problem - the form that was created as Form1 is no longer the "main" form in the application, I added another that calls it. I changed the appropriate code in the Program.cs so that the other form (lets call it Form2) is the first one displayed, and user can call any other from it (there is a total of 5 forms in the application). And of course, when I close Form2, the entire application closes with it - this is fine. But, when I close the Form1, it also closes all other forms, and it shouldn't, it should only close itself and leave Form2 displayed and available for usage. How can I fix this problem?
Thanks
Loading
Pravin GhadgePosted Dec 30, 2011, 4:41 AM
Replace System.Environment.Exit(-1) with this.Close()
& then show Login form.
frmLogin Login=new frmLogin();
Login.Show();
Neven DraskovicPosted Dec 30, 2011, 5:13 AM
Concerning user requests, the problem is that he has no knowledge of programming, so he just gives me new requests when he thinks of some functionality that he forgot about in our previous conversations. It does create some problems for me, but honestly I was prepared for this, so I cope with it as best as I can, and I don't think that will change soon.
Anyway thank you for your help, I thought that I tried the Close method, obviously I was wrong :D
Sam HobbsPosted Dec 30, 2011, 4:50 AM
Also I hope your user understands that it helps to provide all the requirements before any work is done.
It sounds as if it would help to have a better design for managing all the windows and such. I might be able to help but that would require more time than I have at the moment. Hopefully I can get to that later.
Neven DraskovicPosted Dec 30, 2011, 4:08 AM
I'll give the forms logical names so it will be easier for you to follow: Form1 is the "WorkForm" since it does the actual work, Form2 is the "Login" form and Form3 is the "Administration" form.
Let me describe the steps that led me to this problem. When user first gave me his request he just described the functionality he needs - so I created a new project (which of course created the Form1 - WorkForm) and made the required functionality. When I presented the application to the user, he had some additional requests that were not specified in the original request - one of them being the login to the application, so that in the final report he can see who was working on the application in a certain time span. I solved these new requests, and I added a new form (Form2 - Login form) that controls the login process (if the user has the administrator access he can chose between WorkForm (the original problem application) and "Administration" (control of user accounts etc) and if he has the "operator" access WorkForm is automatically opened (obviously he shouldn't be able to access the administration)). I managed to make the application do this, and the functionality is more than satisfactory, except for two problem. First, I need a "logout" functionality (I've put it in a menu strip) that will close the WorkForm or Administration, but leave Login so that another user can log on to the application (I managed to "reset" the Login when a user logs on - this way when forms are closed - by both logout and Close button - the user name and password textBoxes are empty and ready to accept new users), but the previously mentioned problem appears here because when WorkForm is closed, it closes the login form as well (Administration doesn't, that part is working fine). The second thing (I really didn't start working on that so I don't know will it be a problem, but if you have any suggestions please share) is this: How can I restrict the user so that while forms WorkForm or Administration are running, he cant use the Login form (obviously two users can't be logged on at the same time).
I hope that I gave you the informations you need, so if you have any ideas please tell me. Thanks
Sam HobbsPosted Dec 29, 2011, 2:46 PM
VulpesPosted Dec 29, 2011, 11:09 AM
Application.Run(new Form1());
and, if so, are you calling Application.Exit() to close the whole application when Form2 closes?