|
Question : VB.NET Implementing Me.Parent property on class.
|
|
From a user control we can use the me.Parent property to access the properties and methods of the form which holds the user control.
Can anyone give an example of how this could be done on our own classes? I know we could just have a Parent property of the object and pass a reference of the parent into the constructor, however this would create a copy of the parent object into a private variable within the child. Is there a way to only hold a reference to the parent, then when using any of its functions etc use the actual parent object?
|
|
Answer : VB.NET Implementing Me.Parent property on class.
|
|
If you pass the Parent by reference, it will store the address of the Parent itself, not a copy. So in the constructor of the child class, just use ByRef:
Public Sub New(ByRef MyParent As ParentClass) ... End Sub
|
|
|
|