1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Class Objet
Private _name = "Defaut"
Public Property Name As String
Get
Return _name
End Get
Set(value As String)
_name = value
RaiseEvent NameChanged(Me, New EventArgs)
End Set
End Property
Private _value = "Defaut"
Public Property Value As String
Get
Return _value
End Get
Set(value As String)
_value = value
RaiseEvent ValueChanged(Me, New EventArgs)
End Set
End Property
Public Event NameChanged(ByVal sender As Object, ByVal e As EventArgs)
Public Event ValueChanged(ByVal sender As Object, ByVal e As EventArgs)
End Class
Class Objet2
Sub AddEvent(ByVal obj As Object)
AddHandler obj, AddressOf Event_Detected 'compile pas
End Sub
Sub Event_Detected(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("Un évènement a été détecté!")
End Sub
End Class
Module Test
Sub Main()
Dim o As New Objet
Dim o2 As New Objet2
o2.AddEvent(o.NameChanged) 'compile pas
o2.AddEvent(o.ValueChanged) 'compile pas
o.Name = "autre nom" 'déclenchement de o2.Event_Detected()
o.Value = "autre valeur" 'déclenchement de o2.Event_Detected()
End Sub
End Module |
Partager