Alt + F4 is the shortcut to close a form. When I use this shortcut in an MDI enviroment, the application is closed, so obviously the shortcut applies to the 'Container' and not to the 'Childform'.
What would be the best practice to capture this event and close the active child instead of the container
i read about registering Alt + F4 as hotkey when the MDI activates. When the MDI deactivates, unregistering the hotkey. So,the hotkey doesn't effect other windows.
someone, can tell about registering Alt + F4 or something better
You can change the void Dispose(bool disposing)
method in your winform to close your child form instead, like this:
protected override void Dispose(bool disposing)
{
if (/* you need to close a child form */)
{
// close the child form, maybe by calling its Dispose method
}
else
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
EDIT: as my commenter said, instead of modifying the overridden Dispose
method, you should just override the OnFormClosing
method instead, like so:
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (/* you need to close the child form */)
{
e.Cancel = true;
// close the child form, maybe with childForm.Close();
}
else
base.OnFormClosing(e);
}