Search code examples
vb.netwinformseventswinforms-interopraiseevent

RaiseEvent from a UserControl that's placed on a UserControl that's on a Form


I have a Windows Form that contains a custom control container as a UserControl. For the sake of this question, this custom control container is called Dashboard. This container called Dashboard contains numerous other controls depending on their permissions. I need to raise events that are contained on these controls through the Dashboard control and over to the Windows Form.

How can I bubble up the event? I'm using VB.NET for this project, but can convert C# into VB.NET.

Also, to complicate matters, the main Windows Form is a VB6 project. So, I'm using the InteropFormsToolkit to accomplish this.


Solution

  • I figured it out. I just did what I had said that I wanted to do and created an event with a custom eventargs class and bubbled it up to the VB6 app. Each control needed to implement the custom event such as:

    Public Event OnMyCustomEvent(source As Object, e As MyCustomEventArgs)
    

    And continue raising that event up to VB6. In VB6 that event was exposed as a function for me to handle as necessary.