I have several classes that can raise same event: classA, classB, classC all can RaiseEvent "DlFinished", "TableUpdated", "ReportProgress". Since all 3 classes give me about the same information, I created an user control which displays the data. Now this may not be the best way to handle this situation, but I am just starting to learn programming in VB.Net, i handle it like this:
Public Class myUserControl Private WithEvents _d As Object Public Sub New(ByRef d As classA) _d = d InitializeComponent() End Sub Public Sub New(ByRef d As classB) _d = d InitializeComponent() End Sub Public Sub New(ByRef d As classC) _d = d InitializeComponent() End Sub ... End Class
The controls seems to work fine, but they cannot get the events fired by the classes. If I try to handle the events within "myUserControl" with something like :
Private Sub _d_ReportProgress(percentage As Integer, message As String) Handles _d.ReportProgress 'misc code here ... End Sub
i get the following error:
Error 74 Event 'ReportProgress' cannot be found.
I would appreciate any suggestion. I also considered creating a class that has these events (classMain) then having my classA, classB, classC inheriting classMain, but I am not sure that would work either.
Thank you for your help