If you need to know the reason the form is closing then try this:
VB Code:
  1. Public Enum QueryUnloadModes
  2.         SystemShutdown
  3.         TaskManager
  4.         MenuClose
  5.         CodeCall
  6.         Unknown
  7.     End Enum
  8.  
  9.     Public Function QueryUnloadMode() As QueryUnloadModes
  10.         'PURPOSE: This function provides the same functionality that the QueryUnloadMode
  11.         'parameter did when closing a form in VB6.  It returns the reason the form is closing.
  12.         'It has not been tested when run outside of the Closing event but does work as
  13.         'expected when called from the Closing event of a form.
  14.         'SOURCE: Most of the code found here is a variant of the following two sources:
  15.         '   [url]http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=42556[/url]
  16.         '   [url]http://www.gotdotnet.com/community/messageboard/Thread.aspx?id=40651[/url]
  17.         Dim st As New System.Diagnostics.StackTrace(True)
  18.  
  19.         If st.FrameCount >= 15 Then
  20.  
  21.             If st.GetFrame(15).GetMethod.Name <> "WmSysCommand" Then
  22.                 Return QueryUnloadModes.SystemShutdown
  23.             End If
  24.         End If
  25.  
  26.         Dim O As New System.Diagnostics.StackTrace(True)
  27.         Dim F As System.Diagnostics.StackFrame
  28.  
  29.         F = O.GetFrame(8)
  30.  
  31.         Select Case F.GetMethod.Name.ToString
  32.             Case "SendMessage"
  33.                 'Closing because of call in code
  34.                 Return QueryUnloadModes.CodeCall
  35.             Case "CallWindowProc"
  36.                 'Closing because of system menu click
  37.                 Return QueryUnloadModes.MenuClose
  38.             Case "DispatchMessageW"
  39.                 'Closing because of Task Manager
  40.                 Return QueryUnloadModes.TaskManager
  41.             Case Else
  42.                 'Don't Know why I'm closing!!??
  43.                 Return QueryUnloadModes.Unknown
  44.         End Select
  45.  
  46.     End Function

Then just call it from the closing event of the form and it will return the enum value for the reason.

VB Code:
  1. Dim ret As QueryUnloadModes = QueryUnloadMode()
  2.  
  3.         If ret <> QueryUnloadModes.SystemShutdown Then
  4.             e.Cancel = True
  5.             Me.Hide()
  6.         End If

It can also be put in a dll and used from there.