Postponing Close until all application windows are closed
-
I have an application with a main window that shows a gridview of records that can be selected and buttons along the bottom that offer options either updating one of the records or creating a new one. I use the same for for both of these functions I just make cosmetic changes to the title and buttons depending on which function the user chooses. When the user chooses to add a new record to the database a new record is created and loaded into the form. The user may then put whatever data they require into the record then they must then choose to either save the record or cancel out of the form which then deletes the blank record from the database. The only way to close this form is to select one of those options. The problem I am running into is that apparently the users are opening a form to input a new record then becoming distracted by phone calls or other processes and forgetting that they have this form open. When they return to the app they are just closing the main form which of course closes all of it's open forms which then leaves me with blank records in my database. What I would like to do is to perform a check before I close the main window to see if any other windows have been left open and run through my code to delete the database record before the application completely closes. I can use the FindWindow function to check for the open window on the window closing event of my main window but am at a loss as to how to stop the window from closing until I manage the situation. Can anyone offer me any suggestions? Thanks for all your help, Judy
-
I have an application with a main window that shows a gridview of records that can be selected and buttons along the bottom that offer options either updating one of the records or creating a new one. I use the same for for both of these functions I just make cosmetic changes to the title and buttons depending on which function the user chooses. When the user chooses to add a new record to the database a new record is created and loaded into the form. The user may then put whatever data they require into the record then they must then choose to either save the record or cancel out of the form which then deletes the blank record from the database. The only way to close this form is to select one of those options. The problem I am running into is that apparently the users are opening a form to input a new record then becoming distracted by phone calls or other processes and forgetting that they have this form open. When they return to the app they are just closing the main form which of course closes all of it's open forms which then leaves me with blank records in my database. What I would like to do is to perform a check before I close the main window to see if any other windows have been left open and run through my code to delete the database record before the application completely closes. I can use the FindWindow function to check for the open window on the window closing event of my main window but am at a loss as to how to stop the window from closing until I manage the situation. Can anyone offer me any suggestions? Thanks for all your help, Judy
In the Form.FormClosing event, you can cancel the closing, i.e.:
Private Sub Form1\_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 'If there are are windows open, maybe tell the user and switch to them. e.Cancel = True End Sub
Would the "Shutdown mode" option in the project's settings be of any help? Maybe try setting it to "When last form closes."
-
In the Form.FormClosing event, you can cancel the closing, i.e.:
Private Sub Form1\_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 'If there are are windows open, maybe tell the user and switch to them. e.Cancel = True End Sub
Would the "Shutdown mode" option in the project's settings be of any help? Maybe try setting it to "When last form closes."