Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Postponing Close until all application windows are closed

Postponing Close until all application windows are closed

Scheduled Pinned Locked Moved Visual Basic
helpdatabasetutorialquestionlearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JudyV
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • J JudyV

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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."

      J 1 Reply Last reply
      0
      • L Lost User

        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."

        J Offline
        J Offline
        JudyV
        wrote on last edited by
        #3

        Thank you so much JZ! That took care of the problem. I can give the user a message then send the open form to the front so they can close it cleanly. I'll look into the shutdown mode option on the project also. Thanks for all the help, Judy

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups