/// <summary>
        /// Handles the MouseMove event of the imgCurrent control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
        private void imgCurrent_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isDragging)
            {
                var point  = e.GetPosition((IInputElement)sender);
                var width  = point.X - _selectRectangleStartPoint.X;
                var height = point.Y - _selectRectangleStartPoint.Y;

                if (width == 0 || height == 0)
                {
                    return;
                }

                if (width > 0)
                {
                    SelectRectangle.Width = width;
                }
                else
                {
                    _selectRectangleStartPoint.X += width;
                    SelectRectangle.SetValue(Canvas.LeftProperty, _selectRectangleStartPoint.X);
                    SelectRectangle.Width -= width;
                }

                if (height > 0)
                {
                    SelectRectangle.Height = height;
                }
                else
                {
                    _selectRectangleStartPoint.Y += height;
                    SelectRectangle.SetValue(Canvas.TopProperty, _selectRectangleStartPoint.Y);
                    SelectRectangle.Height -= height;
                }
                return;
            }

            if (_isLeftMouseButtonPressed)
            {
                var point  = e.GetPosition((IInputElement)sender);
                var xDelta = point.X - _selectRectangleStartPoint.X;
                var yDelta = point.Y - _selectRectangleStartPoint.Y;
                ImageTranslateX           += xDelta;
                ImageTranslateY           += yDelta;
                _selectRectangleStartPoint = new Point(point.X, point.Y);
            }
        }
        private void imgCurrent_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isDragging)
            {
                var point  = e.GetPosition((IInputElement)sender);
                var width  = point.X - _selectRectangleStartPoint.X;
                var height = point.Y - _selectRectangleStartPoint.Y;

                if (width == 0 || height == 0)
                {
                    return;
                }
                //width = width == 0 ? 1 : width;
                //height = height == 0 ? 1 : height;

                if (width > 0)
                {
                    SelectRectangle.Width = width;
                }
                else
                {
                    _selectRectangleStartPoint.X += width;
                    SelectRectangle.SetValue(Canvas.LeftProperty, _selectRectangleStartPoint.X);
                    SelectRectangle.Width -= width;
                }

                if (height > 0)
                {
                    SelectRectangle.Height = height;
                }
                else
                {
                    _selectRectangleStartPoint.Y += height;
                    SelectRectangle.SetValue(Canvas.TopProperty, _selectRectangleStartPoint.Y);
                    SelectRectangle.Height -= height;
                }
            }
        }
예제 #3
0
        private void OriginalImageContainer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (_isDragging)
            {
                var x = e.GetPosition(BackPlane).X;
                var y = e.GetPosition(BackPlane).Y;
                _currentPointImg.X = e.GetPosition(OriginalImage).X;
                _currentPointImg.Y = e.GetPosition(OriginalImage).Y;
//                Debug.WriteLine("Canvas: x = {0} y = {1} X = {2} Y = {3} Width = {4} Height = {5}", x, y, _anchorPoint.X, _anchorPoint.Y, Math.Abs(x - _anchorPoint.X), Math.Abs(y - _anchorPoint.Y));
//                Debug.WriteLine("Image: x = {0} y = {1} X = {2} Y = {3} Width = {4} Height = {5}", _currentPointImg.X, _currentPointImg.Y, _anchorPointImg.X, _anchorPointImg.Y, Math.Abs(_currentPointImg.X - _anchorPointImg.X), Math.Abs(_currentPointImg.Y - _anchorPointImg.Y));

                SelectRectangle.SetValue(Canvas.LeftProperty, Math.Min(x, _anchorPoint.X));
                SelectRectangle.SetValue(Canvas.TopProperty, Math.Min(y, _anchorPoint.Y));

                SelectRectangle.Width  = Math.Abs(x - _anchorPoint.X);
                SelectRectangle.Height = Math.Abs(y - _anchorPoint.Y);

                if (SelectRectangle.Visibility != Visibility.Visible)
                {
                    SelectRectangle.Visibility = Visibility.Visible;
                }
            }
        }