form2.FormClosed += (sender, eventArgs) => { // some code };
form2.FormClosing += (sender, eventArgs) => { Form senderForm = (Form)sender; // will always cast to this type, no need to check up, see below // some code // but you can also prevent closing of the form based of some condition: if (shouldNotCloseIt /* whatever */ && eventArgs.CloseReason == UserClosing) { eventArgs.Cancel = true; senderForm.Hide(); // typical use of it; actually senderForm == form2, see above } // if // some more code }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)