Trying to have events raised within a class be received within the MainForm when this class is within a Dictionary. Here are some code samples.
Created a Class:
Public Class Zone
Public _ZoneID As Integer
Public _ZoneName As String
Public Event ZoneEntered(ByVal intToolID As Integer, ByVal intZoneID As Integer)
Public Sub New()
End Sub
Public Property ZoneName() As String
Get
Return _ZoneName
End Get
Set(value As String)
_ZoneName = value
End Set
End Property
Public Property ZoneID() As Integer
Get
Return _ZoneID
End Get
Set(value As Integer)
_ZoneID = value
End Set
End Property
Public Sub CheckZone(ByVal intToolID As Integer)
If intToolID > 0 Then
RaiseEvent ZoneEntered(intToolID, _ZoneID)
End If
End Sub
End Class
Within the FormMain code we have:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Zones As New Dictionary(Of Integer, Zone) 'Holds all the Zones for all CameraGroups within this Workspace
Dim NewZone As Zone
NewZone.ZoneName = "TestZone"
NewZone.ZoneID = 123
Zones.Add(1, NewZone)
Dim intZoneID As Integer = 1
If Zones.ContainsKey(intZoneID) Then
Dim ZoneActive As Zone
ZoneActive = Zones(intZoneID)
If Not (ZoneActive Is Nothing) Then
ZoneActive.CheckZone(intZoneID) 'This would fire the event I am looking for
End If
End If
End Sub
How do I setup events from with the class that is part of a dictionary?