-
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
-
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
-
Re: On Form Unload
Try putting your code in the FormClosing event.
-
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.
-
Re: On Form Unload
-
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.