Exemplo n.º 1
0
        internal static bool CouldStartResize(Control control, MouseEventArgs e)
        {
            if (!resizables.TryGetValue(control, out ResizingData resizingData))
            {
                return(false);
            }
            PossibleResizingDirection prd = getPossibleResizingDirection(control, e);

            return((prd.horizontal != ResizingDirection.NoResizing) || (prd.vertical != ResizingDirection.NoResizing));
        }
Exemplo n.º 2
0
        static void control_MouseMove(object sender, MouseEventArgs e)
        {
            Control      typedSender  = (Control)sender;
            ResizingData resizingData = resizables[typedSender];

            if ((resizingData.verticalCurrent == ResizingDirection.NoResizing) && (resizingData.horizontalCurrent == ResizingDirection.NoResizing))
            { // Cursor and start
                Cursor newCursor = null;
                PossibleResizingDirection prd = getPossibleResizingDirection(typedSender, e);
                if ((prd.vertical == prd.horizontal) && (prd.vertical != ResizingDirection.NoResizing))
                {
                    newCursor = Cursors.SizeNWSE;
                }
                else if ((prd.vertical != prd.horizontal) && (prd.vertical != ResizingDirection.NoResizing) && (prd.horizontal != ResizingDirection.NoResizing))
                {
                    newCursor = Cursors.SizeNESW;
                }
                else if (prd.vertical != ResizingDirection.NoResizing)
                {
                    newCursor = Cursors.SizeNS;
                }
                else if (prd.horizontal != ResizingDirection.NoResizing)
                {
                    newCursor = Cursors.SizeWE;
                }

                if (newCursor != null)
                {
                    if (!resizingData.resizingCursor)
                    {
                        resizingData.originalCursor = typedSender.Cursor;
                    }
                    resizingData.resizingCursor = true;
                    typedSender.Cursor          = newCursor;
                }
                else
                {
                    resizingData.resizingCursor = false;
                    typedSender.Cursor          = resizingData.originalCursor;
                }
            }
            else
            { // Resizing
                Point      newMouseOffset = (e.Location - mouseOffset) + new Size(typedSender.Location - new Size(resizingData.originalLocation));
                SizeChange scH            = getNewSize(resizingData.horizontalCurrent, resizingData.originalSize.Width, newMouseOffset.X, resizingData.minWidth, resizingData.maxWidth);
                SizeChange scV            = getNewSize(resizingData.verticalCurrent, resizingData.originalSize.Height, newMouseOffset.Y, resizingData.minHeight, resizingData.maxHeight);
                typedSender.Width    = scH.newSize;
                typedSender.Height   = scV.newSize;
                typedSender.Location = resizingData.originalLocation + new Size(scH.locationDelta, scV.locationDelta);
            }
        }
Exemplo n.º 3
0
        static void control_MouseDown(object sender, MouseEventArgs e)
        {
            Control typedSender           = (Control)sender;
            PossibleResizingDirection prd = getPossibleResizingDirection(typedSender, e);

            if ((prd.vertical != ResizingDirection.NoResizing) || (prd.horizontal != ResizingDirection.NoResizing))
            {
                mouseOffset = new Size(e.Location);
                ResizingData resizingData = resizables[typedSender];
                resizingData.originalLocation  = typedSender.Location;
                resizingData.originalSize      = typedSender.Size;
                resizingData.verticalCurrent   = prd.vertical;
                resizingData.horizontalCurrent = prd.horizontal;
            }
        }
Exemplo n.º 4
0
        private static PossibleResizingDirection getPossibleResizingDirection(Control control, MouseEventArgs e)
        {
            PossibleResizingDirection result = new PossibleResizingDirection()
            {
                vertical   = ResizingDirection.NoResizing,
                horizontal = ResizingDirection.NoResizing
            };

            if (!resizables.TryGetValue(control, out ResizingData resizingData))
            {
                return(result);
            }

            int diffLeft   = e.Location.X;
            int diffRight  = Math.Abs(control.Width - 1 - e.Location.X);
            int diffTop    = e.Location.Y;
            int diffBottom = Math.Abs(control.Height - 1 - e.Location.Y);

            if (diffLeft <= RESIZE_ACCURACY)
            {
                result.horizontal = ResizingDirection.ResizingReverse;
            }
            else if (diffRight <= RESIZE_ACCURACY)
            {
                result.horizontal = ResizingDirection.ResizingForward;
            }

            if (diffTop <= RESIZE_ACCURACY)
            {
                result.vertical = ResizingDirection.ResizingReverse;
            }
            else if (diffBottom <= RESIZE_ACCURACY)
            {
                result.vertical = ResizingDirection.ResizingForward;
            }

            result.vertical   &= resizingData.verticalAllowed;
            result.horizontal &= resizingData.horizontalAllowed;

            return(result);
        }