Results 1 to 6 of 6

Thread: On Form Unload

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    11

    On Form Unload

    Hey,

    I'm trying to add a MsgBox and a few other things when a user exists the program but I can't seem to find the event for the form.

    I tried the "leave" form event but it's not working.

    Any help?

    What I tried and didn't work:
    Code:
        Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
            MsgBox("Bye!")
        End Sub

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: On Form Unload

    did you tried the FormClosing event ?
    Code:
      Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            MessageBox.Show("Bye")
        End Sub
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: On Form Unload

    Try putting your code in the FormClosing event.
    Remember to click on the scales to the left and rep me if I helped

  4. #4
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: On Form Unload

    You must have it in the FormClosing event not in Form1_Leave.
    motil example would be correct and so as The Fire Snake.
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    11

    Re: On Form Unload

    Thanks guys, worked!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: On Form Unload

    It's a small thing but it would actually be more appropriate to use the FormClosed event. The FormClosing event is raised before the form closes and is generally used to stop the form closing under certain circumstances. The FormClosed event is raised after the form is closed.

    That said, it would be more appropriate still to use the Shutdown event of the application itself and not use any event of the form.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width