In C# if I want to create a ‘Custom Event’ you do something like this:
private EventHandler _MyEvent; Public Event EventHandler MyEvent { add{ _MyEvent += value; } remove{ _MyEvent -= Value; } } protected void RaiseMyEvent() { if(_MyEvent != nul) _MyEvent(this, EventArgs.Empty); }
In VB this is not so straightforward nor can I find any help ANYWHERE on the net. This does not work:
private _MyEvent as EventHandler Public Custom Event MyEvent as EventHandler AddHandler(ByVal value as EventHandler) _MyEvent += value 'does not work addhandler _MyEvent, value 'does not work [Delegate].Combine(_MyEvent, value) '_MyEvent still nothing End AddHandler RemoveHandler(ByVal value as EventHandler) 'Same kind of stuff here End RemoveHandler RaiseEvent(sender as Object, e as EventArgs) if(_MyEvent IsNot Nothing) Then '_MyEvent is always nothing _MyEvent.Invoke(sender, e) End If End RaiseEvent End Event
Please help.
Delegates are immutable, so method ‘[Delegate].Combine’ returns new delegate, but not modify the parameters. So you need: