The HandleDestroyed event is called if the closing form is not the main form. If the main form is closed, then the application gets aborted and the events do not fire any more.
I made a test by starting the application like this:
Form1 frmMain = new Form1();
frmMain.Show();
Application.Run();
Now closing the main form does not cancel the application any more. In the form I do this:
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
new Thread(() =>
{
Thread.Sleep(5000); // Give enough time to see the message boxes.
Application.Exit();
}).Start();
}
And now the HandleDestroyed and Disposed events get called on the control.
public Form1()
{
InitializeComponent();
button4.HandleDestroyed += new EventHandler(button4_HandleDestroyed);
button4.Disposed += new EventHandler(button4_Disposed);
}
void button4_Disposed(object sender, EventArgs e)
{
MessageBox.Show("Disposed");
}
void button4_HandleDestroyed(object sender, EventArgs e)
{
MessageBox.Show("HandleDestroyed");
}