Reputation: 3
I've got a usercontrol which should call a Sub of the parent page when it was tapped. But I can't reach it with this.Parent
(or Me.Parent
) and so on.
So how can I access properties and subs from the page class?
Upvotes: 0
Views: 96
Reputation: 27322
You should not call a sub directly from the usercontrol but raise an event and then respond to this event in the Form. I have assumed you are using Winforms.
In the usercontrol:
'declare the event
Public Event ControlClick()
'raise the event when the control is clicked
Private Sub UserControl1_Click(sender As Object, e As System.EventArgs) Handles Me.Click
RaiseEvent ControlClick()
End Sub
In the Form:
Private Sub UserControl1_ControlClick1() Handles UserControl1.ControlClick
MessageBox.Show("Control was clicked")
End Sub
Upvotes: 2