WithEvents and Handles clause necessitates type us to declare the thing variable and the occasion handler as we write http://edition.cnn.com/search/?text=먹튀노트 our code, so linkage is established upon compilation. Conversely, with AddHandler and RemoveHandler, linkage is produced and taken off at runtime, that's more versatile.
Allow’s believe that we want to load numerous MDI baby forms, allowing for each of them to get loaded only once, not to mention to find out when one of several boy or girl kinds is shut. Because We have now a number of varieties to load we want to use the AddHandler and RemoveHandler keywords so we can be flexible and produce the negligible code we will.
Let’s get soiled.
1. In Every single MDI kid variety we must declare a community celebration.
General public Event FormClosed(ByVal f As Variety)
2. In Each individual MDI boy or girl kind we must use the Form_Closed technique which handles the MyBase.Shut class and lift the FormClosed party.
Non-public Sub Form1_Closed(ByVal sender As Item, ByVal e As System.EventArgs) _
Handles MyBase.Shut
RaiseEvent FormClosed(Me)
End Sub
3. On our MDI kind we need to declare two member variables. The first’s of variety Type and the second’s type is ArrayList.
Personal m_f(0) as Type
Personal m_sLoadedChildForms As New ArrayList
four. We must apply a method the will research the MDI child varieties which can be loaded. We’ll also use this process when we unload the MDI little one sorts.
Personal Operate SearchChildForm(ByVal strSearchForm As String, _Optional ByVal idxEventHandler As Extensive = -one) As Extensive

Dim i As Lengthy = 0
For i = 0 To m_sLoadedForms.Depend – 1
If m_sLoadedForms.Product(i) = strSearchForm Then
Dim j As Extensive = 0
For j = m_f.GetLowerBound(0) To m_f.GetUpperBound(0)
If m_f(j).Title = strSearchForm Then idxEventHandler = j
Subsequent j
Return i
Stop If
Upcoming
Return -1
Stop Functionality
five. 먹튀노트 We must implement a method to load the mdi little one varieties and utilize the SearchChildForm technique in order not to load the exact same mdi child sort second time.
Non-public Sub LoadChildForms(ByVal file As Sort)
If m_f.GetUpperBound(0) > 0 Then
ReDim Maintain m_f(m_f.GetUpperBound(0) 1)
m_f(m_f.GetUpperBound(0)) = file I
file Not SearchChildForm(m_f(m_f.GetUpperBound(0)).Name()) >= 0 Then
m_f(m_f.GetUpperBound(0)).MdiParent = Me
AddHandler m_f(m_f.GetUpperBound(0)).Shut, _
AddressOf UnloadChildForm
m_f(m_f.GetUpperBound(0)).Exhibit()
m_sLoadedChildForms.Increase(m_f(m_f.GetUpperBound(0)).Identify)
Else
ReDim Maintain m_f(m_f.GetUpperBound(0) – 1)
6. Ultimately we must carry out a way to just take out our mdi little one type through the array listing so we can easily load it all over again if we want.
Personal Sub UnloadForm(ByVal sender As Process.Object, ByVal e As Procedure.EventArgs)
Dim i As Lengthy
Dim s As String = sender.GetType().Name
Dim IndexForEventHandler = -one
i = SearchChildForm(s, IndexForEventHandler)
If i >= 0 Then m_sLoadedForms.RemoveAt(i)
If IndexForEventHandler >= 0 Then
RemoveHandler m_f(IndexForEventHandler).Closed, AddressOf UnloadForm
m_f(IndexForEventHandler) = Practically nothing