Hi everyone, Normally clicking 'X' button at the top right corner will exit the application. I want my window form application to exit only when holding the 'Shift' click. How can I do that?
+2
A:
You can add a handler to the Closing
event and cancel if the appropriate modifiers are set by checking Keyboard.Modifiers
and cancel as necessary. You may need to add logic to check if the mouse clicked the close button if you wish.
private void Window_Closing(object sender, CancelEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Shift) return; //exit if shift pressed
//cancel by default
e.Cancel = true;
}
Jeff M
2010-08-16 03:48:34