Example #1
0
        public void StartDrag(object sender, MouseButtonEventArgs e)
        {
            UserControl control = sender as UserControl;

            control.CaptureMouse();
            IsDragged = true;
            //GrabPoint = e.GetPosition(this);
        }
        public void InjectAbility(UserControl userControl)
        {
            #region UserControl
            userControl.Cursor = Cursors.SizeAll;
            #endregion

            #region MouseEvents
            userControl.MouseRightButtonDown += (sender, eventArgs) =>
            {
                this.initialUserControlPosition = new Point(Canvas.GetLeft(userControl), Canvas.GetTop(userControl));
                this.initialMousePosition       = eventArgs.GetPosition(userControl);

                userControl.CaptureMouse();
            };

            userControl.MouseMove += (sender, eventArgs) =>
            {
                if (eventArgs.RightButton == MouseButtonState.Pressed)
                {
                    Point newMousePosition   = eventArgs.GetPosition(userControl);
                    Point deltaMousePosition = new Point(this.initialMousePosition.X - newMousePosition.X, this.initialMousePosition.Y - newMousePosition.Y);

                    Point newUserControlPosition = new Point(this.initialUserControlPosition.X - deltaMousePosition.X, this.initialUserControlPosition.Y - deltaMousePosition.Y);
                    Canvas.SetLeft(userControl, newUserControlPosition.X);
                    Canvas.SetTop(userControl, newUserControlPosition.Y);

                    this.initialUserControlPosition = newUserControlPosition;
                }
            };

            userControl.MouseUp += (sender, eventArgs) =>
            {
                userControl.ReleaseMouseCapture();
            };
            #endregion
        }
Example #3
0
 void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     _bMouseCapturing = _oUserCtrl.CaptureMouse();
     _oLastMousePos   = e.GetPosition(null);
 }