RectangleShape Usercontrol Pass Shape_Click Event to Usercontrol_Click in VB.Net

39 Views Asked by At

In VB.Net I am putting a RectangleShape on a user control. When I click on the shape as a usercontrol I want the usercontrol Click Event to Activate. I have tried various things but to no avail. It will fire a button Click but not the Usercontrol Click Event. I am a VB6 programmer trying to learn the VB.net and it is perplexing. I hope somebody out ther knows how to do this many thanks in advance.

I tried many things but not worked. It seems I should be able to send the Shape Click event to the usercontrol Click event but to no avail.

1

There are 1 best solutions below

6
jmcilhinney On

Throughout the .NET framework, an event named ExampleEvent has a corresponding OnExampleEvent method that raises it. If you want to raise a user control's Click event, you call its OnClick method. If you want to raise the container event when the child event is raised, handle the child event and call the OnClick method in the event handler, e.g.

Private Sub ChildControl_Click(sender As Object, e As EventArgs) Handles ChildControl.Click
    OnClick(EventArgs.Empty)
End Sub

To learn more about how events work internally, you might like to read this.