/// <summary> /// Raises the Pressed event. /// </summary> /// <remarks>The Pressed event is executed asynchronously.</remarks> protected virtual void OnPressed() { // Invoke these asychronously in case they're slow. (Testing revealed that Windows will reassert // responsibility for the key stroke(s) if the hookcallback doesn't immediately return.) foreach (EventHandler pressedEvent in Pressed.GetInvocationList()) { pressedEvent.BeginInvoke(this, EventArgs.Empty, ar => ((EventHandler)ar.AsyncState).EndInvoke(ar), pressedEvent); } }
public override void BeforeDispose() { if (Pressed != null) { //Remove all Events associated to this control (That haven't been unsubscribed !) foreach (Delegate d in Pressed.GetInvocationList()) { Pressed -= (EventHandler)d; } } }
public void RemoveHandlers() { if (Pressed != null) { foreach (var d in Pressed.GetInvocationList()) { Pressed -= (ButtonEvent)d; } } if (Released != null) { foreach (var d in Released.GetInvocationList()) { Released -= (ButtonEvent)d; } } }