ActivatedOccurs when the form is activated in code or by the user.
ClickOccurs when the control is clicked. (Inherited from Control.)
DeactivateOccurs when the form loses focus and is no longer the active form.
DoubleClick Occurs when the control is double-clicked. (Inherited from Control.)
FormClosed (Added in 2.0) Occurs after the form is closed.
FormClosing(Added in 2.0) Occurs before the form is closed.
HelpButtonClicked Occurs when the Help button is clicked.
LoadOccurs before a form is displayed for the first time.
ResizeBegin Occurs when a form enters resizing mode.
ResizeEnd Occurs when a form exits resizing mode.
Shown Occurs whenever the form is first displayed.
Disposed 
Invalidated 
LostFocus 
Paint 
Validated 
Validating 


FormClosing Event

Run code if user exits using the X


Private m_sCurrentValues As String 
Private m_bCancelButtonPressed As Boolean
Private m_bFormLoadComplete As Boolean

Private Sub WindowsForm_FormClosing(ByVal sender As Object, _
                        ByVal e As System.Windows.Forms.FormClosing.EventArgs) _
                        Handles Me.FormClosing

Dim objresult As System.Windows.Forms.DialogResult
Dim slatestvalues As String

   Call Tracer_AddSubroutineStart(System.Reflection.MethodBase.GetCurrentMethod)

   If My.Settings.ERROR_OCCURRED = True Then
'Just exit, don't save any changes
      Exit Sub
   End If

   slatestvalues = Me.GetValues_Latest
   If (m_sCurrentValues = sLatestValues) Or (m_bFormLoadComplete = False) Then

      Call Form_Close()
      Me.Dispose()
      Exit Sub

   Else

      If (m_bCancelButtonPressed = True) Then
         If (gSettingsFile.AreYouSureYouWantToCancel = True) Then
            objresult = modQuestions.WindowsForm_ClosingQuestionCancelConfirmation(m_sFORMTITLE)
         Else
            objresult = Windows.Forms.DialogResult.Yes
         End If
          
         If (objresult = Windows.Forms.DialogResult.Yes) Then
            Call Form_Close()
            Me.Dispose()
            Exit Sub
         End If
         If (objresult = Windows.Forms.DialogResult.No) Then
            e.Cancel = True
            Exit Sub
         End If

      Else 'cross in the corner has been used
         objresult = modQuestions.WindowsForm_ClosingQuestionSaveChangesPrompt(m_sFORMTITLE)

         If (objresult = Windows.Forms.DialogResult.Cancel) Then
            e.Cancel = True
            Exit Sub
         End If
         If (objresult = Windows.Forms.DialogResult.Yes) Then
            If (Form_Save() = False) Then
               e.Cancel = True
               Exit Sub
            End If
            Call Form_Close()
            Me.Dispose()
            Exit Sub
         End If
         If (objresult = Windows.Forms.DialogResult.No) Then
            Call Form_Close()
            Me.Dispose()
            Exit Sub
         End If
      End If
   End If

End Sub


Private Sub btnCancel_Click(ByVal sender As System.Object, _ 
                       ByVal e As System.EventArgs) _
                       Handles btnCancel.Click

   Call Tracer_AddSubroutineStart(System.Reflection.MethodBase.GetCurrentMethod)

   m_bCancelButtonPressed = True
   Me.Close()

End Sub




If (e.CloseReason = CloseReason.UserClosing) Then 
End If



© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext