问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/6656965/raiseevent-from-a-usercontrol-thats-placed-on-a-usercontrol-thats-on-a-form