Events

ActivatedOccurs when the form is activated in code or by the user.
AutoSizeChanged  
AutoValidateChanged 
BackColorChanged  
BackgroundImageChanged  
BackgroundImageLayoutChanged  
BindingContextChanged  
CausesValidationChanged  
ChangeUICues  
ClickOccurs when the control is clicked. (Inherited from Control.)
ClientSizeChanged  
Closed 
Closing 
ContextMenuChanged  
ControlAdded  
ControlRemoved  
CursorChanged  
Deactivate 
Disposed 
DockChanged Occurs when the form loses focus and is no longer the active form.
DoubleClick Occurs when the control is double-clicked. (Inherited from Control.)
DragDrop 
DragEnter  
DragLeave  
DragOver  
EnabledChanged  
Enter  
FontChanged  
ForeColorChanged  
FormClosed (Added in 2.0) Occurs after the form is closed.
FormClosing(Added in 2.0) Occurs before the form is closed.
GiveFeedback  
GotFocus  
HandleCreated  
HandleDestroyed  
HelpButtonClicked Occurs when the Help button is clicked.
HelpRequested  
ImeModeChanged  
InputLanguageChanged 
InputLanguageChanging 
Invalidated 
KeyDown  
KeyPress  
KeyUp  
Layout  
Leave  
LoadOccurs before a form is displayed for the first time.
LocationChanged  
LostFocus 
MarginChanged  
MaximizedBoundsChanged 
MaximumSizeChanged 
MdiChildActivate 
MenuComplete 
MenuStart 
MinimumSizeChanged 
MouseCaptureChanged  
MouseClick  
MouseDoubleClick  
MouseDown  
MouseEnter  
MouseHover  
MouseLeave  
MouseUp  
MouseWheel  
Move  
PaddingChanged 
Paint 
ParentChanged  
PreviewKeyDown  
QueryAccessibilityHelp  
RegionChanged  
Resize 
ResizeBegin Occurs when a form enters resizing mode.
ResizeEnd Occurs when a form exits resizing mode.
RightToLeftChanged  
RightToLeftLayoutChanged 
Scroll 
ShownOccurs whenever the form is first displayed.
SizeChanged  
StyleChanged  
SystemColorsChanged  
TabIndexChanged  
TabStopChanged  
TextChanged  
Validated 
Validating 
VisibleChanged  

Load Event

Occurs immediately after the Show or ShowDialog methods
Occurs just before the form is actually displayed.
If you hide and show the form again, this event is not fired
Never add or change the code in the Designer.vb file
This event can be automatically added by double clicking anywhere on the windows form while working in Design mode.


public partial class Form1 : System.Windows.Forms.Form 
{
  private void Form1_Load(object sender, EventArgs e)
  {
    this.Text = "Form Title";
  }
}



FormClosing Event


This event occurs as a form is being closed.
The behaviour of this event is different depending on whether you have a modal or modeless windows form.
You can cancel this event to prevent the form closing by setting the Cancel property to True


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

Activated Event



Disposed Event



Shown Event

Used when loading lengthy data


Windows.Forms.Application.DoEvents



Async Web Services


Using Async Web Services behind a Form

If a call has been made it is possible that the windows form might have been closed before the result has been returned
At the top of all your _Callback subroutines you need to add the following line:


If (Me.Disposed = True) Then Exit Sub 

You must also make sure the form is disposed before it is closed


Private Sub Form_Close() 
   Me.Dispose()
   Me.Close()
End Sub


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext