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.
On Tue, 15 Mar 2005 08:39:08 -0800, waisty vb.net rookie
<wa***************@discussions.microsoft.com> wrote:
Thanks a lot Morten. But i don't understand a single line of code.
The thing is, i'm just a vb.net rookie. But thanks anyhow.
"Morten Wennevik" wrote:
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)
}
--
Happy Coding!
Morten Wennevik [C# MVP]
--
Happy Coding!
Morten Wennevik [C# MVP]