Thursday, July 31, 2014

FormClosing event doesn't work as I want


Hi friends!

First, I have read other similar threads but I haven't seen a complete match.


It is my VB.NET app. I want the user to be logged out when a user closes the form/application by clicking the X at the right-top (to prevent the user from appearing to be online while not).


Now, I created a sub for LoggOff, put it in a module and call it whenever I want it. So I went to properties and double-clicked"Form Closing" event to write the code for FormClosing. Inside FormClose I call the "LogOff" sub explained above, ofcourse, now when the user clicks the big close 'X' at the top, he/she is logged off.But there is a problem;


The first form to load is the login form after which another form, say "Welcome" will be opened and "login" will be closed (by welcome.open, me.close), now the problem is, whenever me.close is executed, all the code in the FormClosing event is also run, which means terminating the application.


Whenever I just want to close one form and open another one (I don't want to just hide forms) the code will log the user off and close the application. How can I differentiate the closing of a user hitting the big X and the closing of a programmer with me.close???


Many thanks for any input.

Frank!





"I can do all things through Him who strengthens me"


No comments:

Post a Comment