Ejemplo n.º 1
0
        private void RegisterBorderEvents(DirectionOfResize DirectionOfResize, FrameworkElement border)
        {
            border.MouseLeftButtonDown += (sender, e) =>
            {
                Point cursorLocation = e.GetPosition(window);
                Point cursorOffset   = new Point();

                switch (DirectionOfResize)
                {
                case DirectionOfResize.Left:
                    cursorOffset.X = cursorLocation.X;
                    break;

                case DirectionOfResize.TopLeft:
                    cursorOffset.X = cursorLocation.X;
                    cursorOffset.Y = cursorLocation.Y;
                    break;

                case DirectionOfResize.Top:
                    cursorOffset.Y = cursorLocation.Y;
                    break;

                case DirectionOfResize.TopRight:
                    cursorOffset.X = (window.Width - cursorLocation.X);
                    cursorOffset.Y = cursorLocation.Y;
                    break;

                case DirectionOfResize.Right:
                    cursorOffset.X = (window.Width - cursorLocation.X);
                    break;

                case DirectionOfResize.BottomRight:
                    cursorOffset.X = (window.Width - cursorLocation.X);
                    cursorOffset.Y = (window.Height - cursorLocation.Y);
                    break;

                case DirectionOfResize.Bottom:
                    cursorOffset.Y = (window.Height - cursorLocation.Y);
                    break;

                case DirectionOfResize.BottomLeft:
                    cursorOffset.X = cursorLocation.X;
                    cursorOffset.Y = (window.Height - cursorLocation.Y);
                    break;
                }

                this.cursorOffset = cursorOffset;

                border.CaptureMouse();
            };

            border.MouseMove += (sender, e) =>
            {
                if (border.IsMouseCaptured)
                {
                    window.SizeToContent = SizeToContent.Manual;
                    Point cursorLocation = e.GetPosition(window);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange   = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange   = (cursorLocation.Y + cursorOffset.Y);

                    switch (DirectionOfResize)
                    {
                    case DirectionOfResize.Left:
                        if (window.Width - nHorizontalChange <= window.MinWidth)
                        {
                            break;
                        }
                        window.Left  += nHorizontalChange;
                        window.Width -= nHorizontalChange;
                        break;

                    case DirectionOfResize.TopLeft:
                        if (window.Width - nHorizontalChange <= window.MinWidth)
                        {
                            break;
                        }
                        window.Left  += nHorizontalChange;
                        window.Width -= nHorizontalChange;
                        if (window.Height - nVerticalChange <= window.MinHeight)
                        {
                            break;
                        }
                        window.Top    += nVerticalChange;
                        window.Height -= nVerticalChange;
                        break;

                    case DirectionOfResize.Top:
                        if (window.Height - nVerticalChange <= window.MinHeight)
                        {
                            break;
                        }
                        window.Top    += nVerticalChange;
                        window.Height -= nVerticalChange;
                        break;

                    case DirectionOfResize.TopRight:
                        if (pHorizontalChange <= window.MinWidth)
                        {
                            break;
                        }
                        window.Width = pHorizontalChange;
                        if (window.Height - nVerticalChange <= window.MinHeight)
                        {
                            break;
                        }
                        window.Top    += nVerticalChange;
                        window.Height -= nVerticalChange;
                        break;

                    case DirectionOfResize.Right:
                        if (pHorizontalChange <= window.MinWidth)
                        {
                            break;
                        }
                        window.Width = pHorizontalChange;
                        break;

                    case DirectionOfResize.BottomRight:
                        if (pHorizontalChange <= window.MinWidth)
                        {
                            break;
                        }
                        window.Width = pHorizontalChange;
                        if (pVerticalChange <= window.MinHeight)
                        {
                            break;
                        }
                        window.Height = pVerticalChange;
                        break;

                    case DirectionOfResize.Bottom:
                        if (pVerticalChange <= window.MinHeight)
                        {
                            break;
                        }
                        window.Height = pVerticalChange;
                        break;

                    case DirectionOfResize.BottomLeft:
                        if (window.Width - nHorizontalChange <= window.MinWidth)
                        {
                            break;
                        }
                        window.Left  += nHorizontalChange;
                        window.Width -= nHorizontalChange;
                        if (pVerticalChange <= window.MinHeight)
                        {
                            break;
                        }
                        window.Height = pVerticalChange;
                        break;
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }
Ejemplo n.º 2
0
        private void RegisterBorderEvents(DirectionOfResize DirectionOfResize, FrameworkElement border)
        {
            border.MouseLeftButtonDown += (sender, e) =>
            {
                Point cursorLocation = e.GetPosition(window);
                Point cursorOffset = new Point();

                switch (DirectionOfResize)
                {
                    case DirectionOfResize.Left:
                        cursorOffset.X = cursorLocation.X;
                        break;
                    case DirectionOfResize.TopLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = cursorLocation.Y;
                        break;
                    case DirectionOfResize.Top:
                        cursorOffset.Y = cursorLocation.Y;
                        break;
                    case DirectionOfResize.TopRight:
                        cursorOffset.X = (window.Width - cursorLocation.X);
                        cursorOffset.Y = cursorLocation.Y;
                        break;
                    case DirectionOfResize.Right:
                        cursorOffset.X = (window.Width - cursorLocation.X);
                        break;
                    case DirectionOfResize.BottomRight:
                        cursorOffset.X = (window.Width - cursorLocation.X);
                        cursorOffset.Y = (window.Height - cursorLocation.Y);
                        break;
                    case DirectionOfResize.Bottom:
                        cursorOffset.Y = (window.Height - cursorLocation.Y);
                        break;
                    case DirectionOfResize.BottomLeft:
                        cursorOffset.X = cursorLocation.X;
                        cursorOffset.Y = (window.Height - cursorLocation.Y);
                        break;
                }

                this.cursorOffset = cursorOffset;

                border.CaptureMouse();
            };

            border.MouseMove += (sender, e) =>
            {
                if (border.IsMouseCaptured)
                {
                    window.SizeToContent = SizeToContent.Manual;
                    Point cursorLocation = e.GetPosition(window);

                    double nHorizontalChange = (cursorLocation.X - cursorOffset.X);
                    double pHorizontalChange = (cursorLocation.X + cursorOffset.X);
                    double nVerticalChange = (cursorLocation.Y - cursorOffset.Y);
                    double pVerticalChange = (cursorLocation.Y + cursorOffset.Y);

                    switch (DirectionOfResize)
                    {
                        case DirectionOfResize.Left:
                            if (window.Width - nHorizontalChange <= window.MinWidth)
                                break;
                            window.Left += nHorizontalChange;
                            window.Width -= nHorizontalChange;
                            break;
                        case DirectionOfResize.TopLeft:
                            if (window.Width - nHorizontalChange <= window.MinWidth)
                                break;
                            window.Left += nHorizontalChange;
                            window.Width -= nHorizontalChange;
                            if (window.Height - nVerticalChange <= window.MinHeight)
                                break;
                            window.Top += nVerticalChange;
                            window.Height -= nVerticalChange;
                            break;
                        case DirectionOfResize.Top:
                            if (window.Height - nVerticalChange <= window.MinHeight)
                                break;
                            window.Top += nVerticalChange;
                            window.Height -= nVerticalChange;
                            break;
                        case DirectionOfResize.TopRight:
                            if (pHorizontalChange <= window.MinWidth)
                                break;
                            window.Width = pHorizontalChange;
                            if (window.Height - nVerticalChange <= window.MinHeight)
                                break;
                            window.Top += nVerticalChange;
                            window.Height -= nVerticalChange;
                            break;
                        case DirectionOfResize.Right:
                            if (pHorizontalChange <= window.MinWidth)
                                break;
                            window.Width = pHorizontalChange;
                            break;
                        case DirectionOfResize.BottomRight:
                            if (pHorizontalChange <= window.MinWidth)
                                break;
                            window.Width = pHorizontalChange;
                            if (pVerticalChange <= window.MinHeight)
                                break;
                            window.Height = pVerticalChange;
                            break;
                        case DirectionOfResize.Bottom:
                            if (pVerticalChange <= window.MinHeight)
                                break;
                            window.Height = pVerticalChange;
                            break;
                        case DirectionOfResize.BottomLeft:
                            if (window.Width - nHorizontalChange <= window.MinWidth)
                                break;
                            window.Left += nHorizontalChange;
                            window.Width -= nHorizontalChange;
                            if (pVerticalChange <= window.MinHeight)
                                break;
                            window.Height = pVerticalChange;
                            break;
                    }
                }
            };

            border.MouseLeftButtonUp += (sender, e) =>
            {
                border.ReleaseMouseCapture();
            };
        }