Exemplo n.º 1
0
        void Target_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (sender as FrameworkElement == null)
            {
                throw new ArgumentException("CoreMouseEvent.cs/CoreMouseEventProcessor/Target_PreviewMouseUp : Can't cover sender to FrameworkElement");
            }
            FrameworkElement Target = sender as FrameworkElement;

            if (Enable[MouseUp])
            {
                CoreMouseEventArgs info1 = new CoreMouseUpEventArgs(CoreMouseEventProcessor.MouseUp, CoreMouseDownEventArgs.LeftButton, e.GetPosition(Target));
                CoreMouseEventArgs info2 = new CoreMouseUpEventArgs(CoreMouseEventProcessor.MouseUp, CoreMouseDownEventArgs.RightButton, e.GetPosition(Target));
                if (e.ChangedButton == MouseButton.Left)
                {
                    OnMouseEvent(info1, Target);
                }
                if (e.ChangedButton == MouseButton.Right)
                {
                    OnMouseEvent(info2, Target);
                }
            }
            if (MouseLeftPressed)
            {
                if (Enable[MouseDragEnd])
                {
                    Point  NowPosition = e.GetPosition(Target);
                    double Distance    = Math.Pow(((MousePressedPoint.X - NowPosition.X) * (MousePressedPoint.X - NowPosition.X) + (MousePressedPoint.Y - NowPosition.Y) * (MousePressedPoint.Y - NowPosition.Y)), 0.5);
                    if (Distance > DragThreshold)
                    {
                        CoreMouseEventArgs info = new CoreMouseDragEndEventArgs(CoreMouseEventProcessor.MouseDragEnd, MousePressedPoint, CoreMouseDragEndEventArgs.LeftButton, NowPosition, Distance);
                        OnMouseEvent(info, Target);
                    }
                }
            }
            if (MouseRightPressed)
            {
                if (Enable[MouseDragEnd])
                {
                    Point  NowPosition = e.GetPosition(Target);
                    double Distance    = Math.Pow(((MousePressedPoint.X - NowPosition.X) * (MousePressedPoint.X - NowPosition.X) + (MousePressedPoint.Y - NowPosition.Y) * (MousePressedPoint.Y - NowPosition.Y)), 0.5);
                    if (Distance > DragThreshold)
                    {
                        CoreMouseEventArgs info = new CoreMouseDragEndEventArgs(CoreMouseEventProcessor.MouseDragEnd, MousePressedPoint, CoreMouseDragEndEventArgs.RightButton, NowPosition, Distance);
                        OnMouseEvent(info, Target);
                    }
                }
            }
            if (e.ChangedButton == MouseButton.Left)
            {
                MouseLeftPressed = false;
            }
            if (e.ChangedButton == MouseButton.Right)
            {
                MouseRightPressed = false;
            }
        }
 void Target_PreviewMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (sender as FrameworkElement == null)
         throw new ArgumentException("CoreMouseEvent.cs/CoreMouseEventProcessor/Target_PreviewMouseUp : Can't cover sender to FrameworkElement");
     FrameworkElement Target = sender as FrameworkElement;
     if (Enable[MouseUp])
     {
         CoreMouseEventArgs info1 = new CoreMouseUpEventArgs(CoreMouseEventProcessor.MouseUp, CoreMouseDownEventArgs.LeftButton, e.GetPosition(Target));
         CoreMouseEventArgs info2 = new CoreMouseUpEventArgs(CoreMouseEventProcessor.MouseUp, CoreMouseDownEventArgs.RightButton, e.GetPosition(Target));
         if (e.ChangedButton == MouseButton.Left)
             OnMouseEvent(info1, Target);
         if (e.ChangedButton == MouseButton.Right)
             OnMouseEvent(info2, Target);
     }
     if(MouseLeftPressed)
     {
         if(Enable[MouseDragEnd])
         {
             Point NowPosition = e.GetPosition(Target);
             double Distance = Math.Pow(((MousePressedPoint.X - NowPosition.X) * (MousePressedPoint.X - NowPosition.X) + (MousePressedPoint.Y - NowPosition.Y) * (MousePressedPoint.Y - NowPosition.Y)), 0.5);
             if (Distance > DragThreshold)
             {
                 CoreMouseEventArgs info = new CoreMouseDragEndEventArgs(CoreMouseEventProcessor.MouseDragEnd, MousePressedPoint, CoreMouseDragEndEventArgs.LeftButton, NowPosition, Distance);
                 OnMouseEvent(info, Target);
             }
         }
     }
     if (MouseRightPressed)
     {
         if (Enable[MouseDragEnd])
         {
             Point NowPosition = e.GetPosition(Target);
             double Distance = Math.Pow(((MousePressedPoint.X - NowPosition.X) * (MousePressedPoint.X - NowPosition.X) + (MousePressedPoint.Y - NowPosition.Y) * (MousePressedPoint.Y - NowPosition.Y)), 0.5);
             if (Distance > DragThreshold)
             {
                 CoreMouseEventArgs info = new CoreMouseDragEndEventArgs(CoreMouseEventProcessor.MouseDragEnd, MousePressedPoint, CoreMouseDragEndEventArgs.RightButton, NowPosition, Distance);
                 OnMouseEvent(info, Target);
             }
         }
     }
     if(e.ChangedButton == MouseButton.Left)
         MouseLeftPressed = false;
     if(e.ChangedButton == MouseButton.Right)
         MouseRightPressed = false;
 }