c# - How to Close Child Window Using Alt + F4 Key? -
alt + f4 shortcut close form. when use shortcut in mdi enviroment, application closed, shortcut applies 'container' , not 'childform'.
what best practice capture event , close active child instead of container
i read registering alt + f4 hotkey when mdi activates. when mdi deactivates, unregistering hotkey. so,the hotkey doesn't effect other windows.
someone, can tell registering alt + f4 or better
you can change void dispose(bool disposing)
method in winform close child form instead, this:
protected override void dispose(bool disposing) { if (/* need close child form */) { // close child form, maybe calling dispose method } else { if (disposing && (components != null)) { components.dispose(); } base.dispose(disposing); } }
edit: commenter said, instead of modifying overridden dispose
method, should override onformclosing
method instead, so:
protected override void onformclosing(formclosingeventargs e) { if (/* need close child form */) { e.cancel = true; // close child form, maybe childform.close(); } else base.onformclosing(e); }
Comments
Post a Comment