示例#1
0
        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
            }
        }
示例#2
0
 public void ClearEvents()
 {
     if (Click != null)
     {
         foreach (Delegate d in Click.GetInvocationList())
         {
             Click -= (EventHandler)d;
         }
     }
 }
示例#3
0
 public bool HasListeners()
 {
     if (Click != null && Click.GetInvocationList().Length > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#4
0
 void doClick()
 {
     foreach (RoutedEventHandler h in Click.GetInvocationList())
     {
         try
         {
             h(this, null);
         }
         catch (Exception)
         {
             Console.WriteLine("A listener threw an exception in its handler");
         }
     }
 }