How to disable Ctrl+F4?

  • Thread starter Richard Lewis Haggard
  • Start date
R

Richard Lewis Haggard

Is there an easy way to disable the hotkey sequence Control F4 or otherwise
prevent the action from killing off MDI child windows in VS05/WinForms 2?
I've already figured out how to get rid of the 'x' in the caption bar but
the hot key sequence is still allowing users to kill off MDI child windows,
which I need to prevent from happening.
 
D

DeveloperX

Add code to the Closing evening for the child form and set e.cancel =
true; in those cases you don't want it to close.
 
B

Ben Voigt

DeveloperX said:
Add code to the Closing evening for the child form and set e.cancel =
true; in those cases you don't want it to close.

Use the FormClosing event so you get CloseReason:

ApplicationExitCall The Exit method of the Application class was invoked.
FormOwnerClosing The owner form is closing.
MdiFormClosing The parent form of this multiple document interface (MDI)
form is closing.
None The cause of the closure was not defined or could not be determined.
TaskManagerClosing The Microsoft Windows Task Manager is closing the
application.
UserClosing The user is closing the form through the user interface (UI),
for example by clicking the Close button on the form window, selecting Close
from the window's control menu, or pressing ALT+F4.
WindowsShutDown The operating system is closing all applications before
shutting down.

Then test for UserClosing
 
R

Richard Lewis Haggard

Thanks for the suggestions. However, there was a problem in that the MDI
child forms were not being built by me and so I did not have control over
what the classes contained and couldn't enforce that all of the individual
MDI children implement their own protection against user closing. It turned
out that there is an easier way to handle the situation. Each MDI child has
an event notification list that is happy to accept an additional event
handler that resides in the main application. At the time that I created the
MDI child window(s) I also appended my own handler to the child's event
notification list. This gives something like this:

// In the code that creates an MDI child...
childForm.FormClosing += New FormClosingEventHandler(
ChildFormClosingEventhandler );

// Later in the module, the actual event handler itself...
public void ChildFormClosingEventHandler(Object sender, FormClosingEventArgs
e)
{
if (CloseReason.UserClosing == e.CloseReason)
e.Cancel = true;
}

Works like a champ!
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Ben Voigt said:
DeveloperX said:
Add code to the Closing evening for the child form and set e.cancel =
true; in those cases you don't want it to close.

Use the FormClosing event so you get CloseReason:

ApplicationExitCall The Exit method of the Application class was invoked.
FormOwnerClosing The owner form is closing.
MdiFormClosing The parent form of this multiple document interface (MDI)
form is closing.
None The cause of the closure was not defined or could not be determined.
TaskManagerClosing The Microsoft Windows Task Manager is closing the
application.
UserClosing The user is closing the form through the user interface (UI),
for example by clicking the Close button on the form window, selecting
Close from the window's control menu, or pressing ALT+F4.
WindowsShutDown The operating system is closing all applications before
shutting down.

Then test for UserClosing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Can't Capture Ctrl-F4 in MDI Form 3
Disable Ctrl+F4 5
Ctrl+F4 4
Prevent Ctrl+Tab in MDI App 1
Disable Ctrl-Break 4
How to disable Ctrl+ALT+DEL and ALT+F4 1
How to disable Alt-F4? 2
How to disable Ctrl+alt+del 2

Top