Public Class Events Not Seen Outside Class RRS feed

  • Question

  • I've got an issue where Public Events in a class aren't being seen outside the class.

    Code looks like this:

    Public Class Class1 
      Public Event Event1(someargs as object) 
      Public Sub New() 
        'Perform Some Code 
        RaiseEvent Event1(someargs) 
      End Sub 
    End Class 

    When I put an event handler for Event1 in the Class itself it works just fine, but I can't catch that same event in the Windows Form that instantiated the Class Object.  Help?
    Tuesday, March 3, 2009 7:22 PM


  • Don't know why you would raise an event in a constructor, but this does:

    Public Class Form1  
      Dim WithEvents C1 As New class1  
      Class class1  
        Event Event1(ByVal e As EventArgs)  
        Sub New()  
          RaiseEvent Event1(New EventArgs)  
        End Sub 
        Private Sub class1_Event1(ByVal e As System.EventArgs) Handles Me.Event1  
          MsgBox("Event1 called")  
        End Sub 
      End Class 
    End Class 
    • Marked as answer by Riquel_Dong Monday, March 9, 2009 6:40 AM
    Tuesday, March 3, 2009 10:00 PM