public void Update(MouseState mouseState) { if (Click != null && Click.GetInvocationList().Length > 0) { MouseArea = new Rectangle(mouseState.X, mouseState.Y, MouseArea.Width, MouseArea.Height); if (Area.Intersects(MouseArea)) { Image.Color = HoverColor; if (mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released) { Image.Color = ClickColor; OnClick(new EventArgs()); } oldMouseState = mouseState; } else { Image.Color = DefaultColor; } } else { // disable button since it has nothing attached } }
public void ClearEvents() { if (Click != null) { foreach (Delegate d in Click.GetInvocationList()) { Click -= (EventHandler)d; } } }
public bool HasListeners() { if (Click != null && Click.GetInvocationList().Length > 0) { return(true); } else { return(false); } }
void doClick() { foreach (RoutedEventHandler h in Click.GetInvocationList()) { try { h(this, null); } catch (Exception) { Console.WriteLine("A listener threw an exception in its handler"); } } }