WithEvents and Handles clause calls for 먹튀검증 sort us to declare the object variable as well as the occasion handler as we create our code, so linkage is designed on compilation. Alternatively, with AddHandler and RemoveHandler, linkage is created and eliminated at runtime, that's additional flexible.
Allow’s assume that we want to load quite a few MDI child types, permitting Every of them to get loaded only once, not to mention to be aware of when one of many youngster kinds is closed. Since Now we have many types to load we would like to use the AddHandler and RemoveHandler key phrases so we can easily be flexible and generate the minimum code we will.
Let’s get dirty.
one. In Every MDI kid kind we really need to declare a public party.
Community Function FormClosed(ByVal f As Type)
two. In Every single MDI child kind we really need to use the Form_Closed approach which handles the MyBase.Shut course and raise the FormClosed celebration.
Private Sub Form1_Closed(ByVal sender As Item, ByVal e As Method.EventArgs) _
Handles MyBase.Shut
RaiseEvent FormClosed(Me)
Close Sub
3. On our MDI variety we need to declare two member variables. The first’s of form Form and the second’s style is ArrayList.
Personal m_f(0) as Kind
Non-public m_sLoadedChildForms As New ArrayList

four. We have to apply a way the will lookup the MDI kid forms which can be loaded. We’ll also use this process when we unload the MDI youngster varieties.
Non-public Purpose SearchChildForm(ByVal strSearchForm As String, _Optional ByVal idxEventHandler As Very long = -1) As Long
Dim i As Very long = 0
For i = 0 To m_sLoadedForms.Count – 1
If m_sLoadedForms.Item(i) = strSearchForm Then
Dim j As Prolonged = 0
For j = m_f.GetLowerBound(0) To m_f.GetUpperBound(0)
If m_f(j).Name = strSearchForm Then idxEventHandler = j
Future j
Return i
Conclude If
Subsequent
Return -1
Stop Purpose
5. We need to implement a method to load the mdi youngster kinds and make use of the SearchChildForm system to be able to not load a similar mdi baby variety 2nd time.
Non-public Sub LoadChildForms(ByVal file As Form)
If m_f.GetUpperBound(0) > 0 Then
ReDim Protect m_f(m_f.GetUpperBound(0) 1)
m_f(m_f.GetUpperBound(0)) = f 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)).Closed, _
AddressOf UnloadChildForm
m_f(m_f.GetUpperBound(0)).Display()
m_sLoadedChildForms.Add(m_f(m_f.GetUpperBound(0)).Title)
Else
ReDim Protect m_f(m_f.GetUpperBound(0) – 1)
6. Ultimately we need to carry out a way to acquire out our mdi kid form in the array listing so we are able to load it once more if we want.
Private Sub UnloadForm(ByVal sender As Program.Object, ByVal e As Method.EventArgs)
Dim i As Prolonged
Dim s As String = sender.GetType().Title
Dim IndexForEventHandler = -1
i = SearchChildForm(s, IndexForEventHandler)
If i >= 0 Then m_sLoadedForms.RemoveAt(i)
If IndexForEventHandler >= 0 Then
RemoveHandler m_f(IndexForEventHandler).Shut, AddressOf UnloadForm
m_f(IndexForEventHandler) = Nothing