Below is a sample of some code I am working with. I need to be able to declare a class as a generic object because I will load a different class based on some user selection. The code works OK but I wondering if there is a way to use the AddHandler without having to convert my object every time. If I don't put in the CType I can't compile because it tells me sampleEvent is not an event of 'Object'. I can access all my properties and methods just fine without using the CType each time but not my events. Any suggestions?
Code:
Public obj As Object
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
obj = New Test
obj = cType(obj, Test)
AddHandler [B]CType(obj, Test).sampleEvent[/B], AddressOf junk
obj.sampleProperty = "hello"
End Sub