When you create a delegate pointing to an instance method, you have to provide the "
" object which will be used when the delegate is invoked. Because you haven't done that, and you've specified
parameter, your delegate instance will be set to
There are two ways you can solve this:
To create a delegate bound to a single instance of the class, use one of the
overloads which accept a
Dim myDelegate As delegate_OnClick = [Delegate].CreateDelegate(
Delegate.CreateDelegate Method (Type, Object, MethodInfo) (System)
To create a delegate which can be reused with multiple instances of the class, give your delegate an extra parameter to represent the object instance:
Private Delegate Sub delegate_OnClick(ByVal instance As YourControlType, ByVal e As EventArgs)
Dim myDelegate As delegate_OnClick = [Delegate].CreateDelegate(GetType(delegate_OnClick), myInfo, True)
The type of the first parameter for the delegate must be the type where the method is declared, or a derived type. If you want to pass an interface, then the
must come from the interface, not the class.