0

Is there a way to call a function in a C# Windows forms application before the application exits, independent of the event that closed the application (i.e. closing by pressing 'X', terminating through taskmanager, etc.)

Sorry I didn't see that the question was already answered but the formulation of the question didn't let me find what I was looking for!

Steffen
  • 3
  • 4

1 Answers1

0

Try FormClosing event:

public Form1()
{
    InitializeComponent();
    FormClosing += Form1_FormClosing;
}

void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    //Do your stuff before form is closed
}
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109