示例#1
0
        private bool IsMouseOverBorder(Point globalPosition)
        {
            //Point coordsInComponentSpace = _component.GlobalToLocal(globalPosition);

            //_l = InRange(coordsInComponentSpace.X, 0, BorderWeight, true) && InRange(coordsInComponentSpace.Y, 0, _component.Height, true);
            //_r = InRange(coordsInComponentSpace.X, _component.Width - BorderWeight, _component.Width, true) && InRange(coordsInComponentSpace.Y, 0, _component.Height, true);
            //_t = InRange(coordsInComponentSpace.Y, 0, BorderWeight, true) && InRange(coordsInComponentSpace.X, 0, _component.Width, true);
            //_b = InRange(coordsInComponentSpace.Y, _component.Height - BorderWeight, _component.Height, true) && InRange(coordsInComponentSpace.X, 0, _component.Width, true);

            var leftBorder   = _component.LocalToGlobal(new Rectangle(0, 0, BorderWeight, _component.Height));
            var rightBorder  = _component.LocalToGlobal(new Rectangle(_component.Width - BorderWeight, 0, BorderWeight, _component.Height));
            var topBorder    = _component.LocalToGlobal(new Rectangle(0, 0, _component.Width, BorderWeight));
            var bottomBorder = _component.LocalToGlobal(new Rectangle(0, _component.Height - BorderWeight, _component.Width, BorderWeight));

            _l = leftBorder.Contains(globalPosition);
            _r = rightBorder.Contains(globalPosition);
            _t = topBorder.Contains(globalPosition);
            _b = bottomBorder.Contains(globalPosition);

            bool isResizing = true;

            if (_l && _t)
            {
                _resizeMode = ResizeMode.TopLeft;
            }
            else if (_r && _t)
            {
                _resizeMode = ResizeMode.TopRight;
            }
            else if (_l && _b)
            {
                _resizeMode = ResizeMode.BottomLeft;
            }
            else if (_r && _b)
            {
                _resizeMode = ResizeMode.BottomRight;
            }
            else if (_l)
            {
                _resizeMode = ResizeMode.Left;
            }
            else if (_r)
            {
                _resizeMode = ResizeMode.Right;
            }
            else if (_t)
            {
                _resizeMode = ResizeMode.Top;
            }
            else if (_b)
            {
                _resizeMode = ResizeMode.Bottom;
            }
            else
            {
                isResizing = false;
            }

            return(isResizing);
        }