samedi 28 février 2015

Winforms communication efficienct approach c#

here is what I am trying to accomplish. I want to make an application with two forms. A login form and the main form that is displayed after login. The login form will allow the user to add his details and store them into a file for the next time he opens the app. When the user successfully logs, he does not have to write those details anymore. The next time he opens the application the main form is displayed right away. So, when the user opens the app, the two forms are originally hidden (minimized / notintaskbar). The application will check if settings file is there and attempts to login then displays the main form if its successful. If it cannot read / login the login form is displayed. Now, here is my question. how do I implement this efficiently.


Originally, I have started the login form as the entry point in main.cs. The logic is handled and if the login is successful it displays the second form. Though, if I close the login form at this point it will close the application since its the entry point. So, I could get around this by hiding the login form and continuing with the main form. Though, I do not like the approach. So, I went ahead and made the main form the entry on main.cs. I would call the login form which will handle the check (settings/login) and do it like mentioned. Though, when I display the hidden main form and attempt to close the login form (from within the login form). It causes the application to close. I am trying a third approach now where I handle the logic on main form and call the login form with showdialog instead of show. Then, I would do the logic on login and return only if I am successful.


I just want to know what is the most efficient approach to accomplish what I am trying to do. Thanks.


Aucun commentaire:

Enregistrer un commentaire