Well, you could override the KeyDown/KeyPress and ignore those
combinations, or handle the OnClosing event and check for what kind of
closing is performed
protected override void OnClosing(CancelEventArgs e)
{
System.Diagnostics.StackTrace O = new System.Diagnostics.StackTrace(true);
System.Diagnostics.StackFrame F = O.GetFrame(7);
if(F.GetMethod().Name == "DefWndProc")
e.Cancel = true; // user ended the application (ALT-F4, clicking the
corner X etc)
}
The VB.NET code should be very similar. The StackTrace class is used for
debugging purposes as it contains a trace of methods called in your
application put into StackFrames, the 8th last StackFrame will reveal what
triggered the OnClosing event so we retrieve the StackFrame and compare
the Method Name with known values like "DefWndProc" = User ended the
application by means of ALT-F4 etc, "SendMessage" = this/Me.Close() was
called from within your application, "DispatchMessageW" = User ended the
application by means of the TaskManager (aborting process) etc.
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.