Blue.Windows.StickyWindow.Resize C# (CSharp) Метод

Resize() приватный Метод

private Resize ( Point p ) : void
p Point
Результат void
        private void Resize( Point p )
        {
            p = originalForm.PointToScreen ( p );
            Screen activeScr = Screen.FromPoint( p );
            formRect = originalForm.Bounds;

            int iRight			= formRect.Right;
            int iBottom			= formRect.Bottom;

            // no normalize required
            // first strech the window to the new position
            if ( (resizeDirection & ResizeDir.Left) == ResizeDir.Left )
            {
                formRect.Width	= formRect.X - p.X + formRect.Width;
                formRect.X		= iRight - formRect.Width;
            }
            if ( (resizeDirection & ResizeDir.Right) == ResizeDir.Right )
                formRect.Width	= p.X - formRect.Left;

            if ( (resizeDirection & ResizeDir.Top) == ResizeDir.Top )
            {
                formRect.Height		= formRect.Height - p.Y + formRect.Top;
                formRect.Y			= iBottom - formRect.Height;
            }
            if ( (resizeDirection & ResizeDir.Bottom) == ResizeDir.Bottom )
                formRect.Height	= p.Y - formRect.Top;

            // this is the real new position
            // now, try to snap it to different objects (first to screen)

            // CARE !!! We use "Width" and "Height" as Bottom & Right!! (C++ style)
            //formOffsetRect = new Rectangle ( stickGap + 1, stickGap + 1, 0, 0 );
            formOffsetRect.X	= stickGap + 1;
            formOffsetRect.Y	= stickGap + 1;
            formOffsetRect.Height = 0;
            formOffsetRect.Width  = 0;

            if ( stickToScreen )
                Resize_Stick ( activeScr.WorkingArea, false );

            if ( stickToOther )
            {
                // now try to stick to other forms
                foreach ( Form sw in GlobalStickyWindows )
                {
                    if ( sw != this.originalForm )
                        Resize_Stick( sw.Bounds, true );
                }
            }

            // Fix (clear) the values that were not updated to stick
            if ( formOffsetRect.X		== stickGap+1 )
                formOffsetRect.X		= 0;
            if ( formOffsetRect.Width	== stickGap+1 )
                formOffsetRect.Width	= 0;
            if ( formOffsetRect.Y		== stickGap+1 )
                formOffsetRect.Y		= 0;
            if ( formOffsetRect.Height	== stickGap+1 )
                formOffsetRect.Height	= 0;

            // compute the new form size
            if ( (resizeDirection & ResizeDir.Left) == ResizeDir.Left )
            {	// left resize requires special handling of X & Width acording to MinSize and MinWindowTrackSize
                int iNewWidth = formRect.Width + formOffsetRect.Width + formOffsetRect.X;

                if ( originalForm.MaximumSize.Width != 0 )
                    iNewWidth		= Math.Min ( iNewWidth, originalForm.MaximumSize.Width );

                iNewWidth		= Math.Min ( iNewWidth, SystemInformation.MaxWindowTrackSize.Width );
                iNewWidth		= Math.Max ( iNewWidth, originalForm.MinimumSize.Width );
                iNewWidth		= Math.Max ( iNewWidth, SystemInformation.MinWindowTrackSize.Width );

                formRect.X		= iRight - iNewWidth;
                formRect.Width	= iNewWidth;
            }
            else
            {	// other resizes
                formRect.Width	+= formOffsetRect.Width  + formOffsetRect.X;
            }

            if ( (resizeDirection & ResizeDir.Top) == ResizeDir.Top )
            {
                int iNewHeight	= formRect.Height + formOffsetRect.Height + formOffsetRect.Y;

                if ( originalForm.MaximumSize.Height != 0 )
                    iNewHeight		= Math.Min ( iNewHeight, originalForm.MaximumSize.Height );

                iNewHeight		= Math.Min ( iNewHeight, SystemInformation.MaxWindowTrackSize.Height );
                iNewHeight		= Math.Max ( iNewHeight, originalForm.MinimumSize.Height );
                iNewHeight		= Math.Max ( iNewHeight, SystemInformation.MinWindowTrackSize.Height );

                formRect.Y		= iBottom - iNewHeight;
                formRect.Height	= iNewHeight;
            }
            else
            {	// all other resizing are fine
                formRect.Height	+= formOffsetRect.Height + formOffsetRect.Y;
            }

            // Done !!
            originalForm.Bounds = formRect;
        }