I've been looking around the internet and I haven't really found any solution to my problem. Is there a way to perform a function when a user closes the form either by pressing the X button in the top right hand corner? I am using a database that saves what form the user is currently looking at, and when the application is closed I want to say "offline."

Any assistance would be appreciated!

Recommended Answers

Use FormClosed when you want to execute something when the form is closed.

Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
     ''Your code here
End Sub

Use the following code FormClosing if you want to execute something right before the form close.


       
Jump to Post

All 4 Replies

Use the form closing event

And what is the code for this? I'm unfamiliar with it.

Use FormClosed when you want to execute something when the form is closed.

Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
     ''Your code here
End Sub

Use the following code FormClosing if you want to execute something right before the form close.

Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
     ''Your code here
End Sub

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.