在C#中如果我想创建一个“自定义事件”,你可以这样做:
private EventHandler _MyEvent; Public Event EventHandler MyEvent { add{ _MyEvent += value; } remove{ _MyEvent -= Value; } } protected void RaiseMyEvent() { if(_MyEvent != nul) _MyEvent(this,EventArgs.Empty); }
在VB中,这不是那么简单,我也无法在网上找到任何帮助.
这不起作用:
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
请帮忙.