Super Dave
New member
- Joined
- Jul 3, 2009
- Messages
- 4
- Programming Experience
- 3-5
I can't seem to find a lot on how to use events in nested objects. I suspect that I should have access to the events in the nested objects through intellisense if I had done things right. I have many objects with 50 or so properties and I would like to access them with out adding handlers for each one and additional events in parent objects.
Can you direct or show me the best practice for how this should be handled?
Example:
Can you direct or show me the best practice for how this should be handled?
Example:
VB.NET:
Public Class Form1
Dim WithEvents myCombinedClass As New CombinedClass
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'AddHandler myCombinedClass.MyClass1.Test1Changed, AddressOf OnText1TextChanged < It can see it here if I uncomment it but why not in the handles argument?
'AddHandler myCombinedClass.MyClass2.Test2Changed, AddressOf OnText2TextChanged
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
'RemoveHandler myCombinedClass.MyClass1.Test1Changed, AddressOf OnText1TextChanged
End Sub
Sub OnText1TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) ' How to you get the handles to recognize the events in myCombinedClass.MyClass1
End Sub
Sub OnText2TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) ' How to you get the handles to recognize the events in myCombinedClass.MyClass2
End Sub
Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonButton1.Click
myCombinedClass.MyClass1.Test1 = "Hello"
myCombinedClass.MyClass2.Test2 = "Goodbye"
End Sub
End Class
Public Class CombinedClass
Private _MyClass1 As New Class1
Private _MyClass2 As New Class2
Sub New()
End Sub
Public Property MyClass1 As Class1
Get
Return _MyClass1
End Get
Set(ByVal value As Class1)
_MyClass1 = value
End Set
End Property
Public Property MyClass2 As Class2
Get
Return _MyClass2
End Get
Set(ByVal value As Class2)
_MyClass2 = value
End Set
End Property
End Class
Public Class Class1
Private _Test1 As String
''' <summary>
''' Occurs when [test1 changed].
''' </summary>
Public Event Test1Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
Sub New()
End Sub
''' <summary>
''' Gets or sets the test1.
''' </summary>
''' <value>The test1.</value>
Public Property Test1 As String
Get
Return _Test1
End Get
Set(ByVal value As String)
_Test1 = value
RaiseEvent Test1Changed(Me, System.EventArgs.Empty)
End Set
End Property
End Class
Public Class Class2
Private _Test2 As String
Public Event Test2Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
Sub New()
End Sub
Public Property Test2 As String
Get
Return _Test2
End Get
Set(ByVal value As String)
_Test2 = value
RaiseEvent Test2Changed(Me, System.EventArgs.Empty)
End Set
End Property
End Class
Last edited by a moderator: