private void ProcessWindowPosChanging(ref WINDOWPOS r)
        {
            Rectangle ScreenBounds = Screen.FromHandle(this.Handle).Bounds;
            if (r.x == 0 && r.y == 0 && r.cx == 0 && r.cy == 0)
                return;
            foreach (IntPtr k in Program.snappingManager.bounds.Keys)
            {
                Rectangle v = Program.snappingManager.bounds[k];
                if (k != this.Handle)
                {

                    if (Math.Abs(r.x + r.cx - v.Left) < SNAPTHRESHOLD)
                    {
                        r.x = v.Left - r.cx;
                    }

                    if (Math.Abs(r.x - (v.Left + v.Width)) < SNAPTHRESHOLD)
                    {
                        r.x = v.Left + v.Width;
                    }

                    if (Math.Abs((r.x + r.cx) - (v.Left + v.Width)) < SNAPTHRESHOLD)
                    {
                        r.x = v.Left + v.Width - r.cx;
                    }

                    if (Math.Abs(r.x - v.Left) < SNAPTHRESHOLD)
                    {
                        r.x = v.Left;
                    }

                    if (Math.Abs(r.y - v.Top) < SNAPTHRESHOLD)
                    {
                        r.y = v.Top;
                    }

                    if (Math.Abs(r.y + r.cy - v.Top) < SNAPTHRESHOLD)
                    {
                        r.y = v.Top - r.cy;
                    }

                    if (Math.Abs(r.y - (v.Top + v.Height)) < SNAPTHRESHOLD)
                    {
                        r.y = v.Top + v.Height;
                    }

                    if (Math.Abs((r.y + r.cy) - (v.Top + v.Height)) < SNAPTHRESHOLD)
                    {
                        r.y = v.Top + v.Height - r.cy;
                    }

                }
            }
        }
        private void ProcessWindowPosChangingSizing(ref WINDOWPOS r)
        {
            Rectangle ScreenBounds = Screen.FromHandle(this.Handle).Bounds;
            if (r.x == 0 && r.y == 0 && r.cx == 0 && r.cy == 0)
                return;
            foreach (IntPtr k in Program.snappingManager.bounds.Keys)
            {
                Rectangle v = Program.snappingManager.bounds[k];
                if (k != this.Handle)
                {

                    if (Math.Abs(r.x + r.cx - v.Right) < SNAPTHRESHOLD)
                    {
                        r.cx = v.Right - r.x;
                    }

                    if (Math.Abs(r.x + r.cx - v.Left) < SNAPTHRESHOLD)
                    {
                        r.cx = v.Left - r.x;
                    }

                    if (Math.Abs(r.x - v.Left) < SNAPTHRESHOLD)
                    {
                        int diff = r.x - v.Left;
                        r.x = v.Left;
                        r.cx += diff;
                    }

                    if (Math.Abs(r.x - v.Right) < SNAPTHRESHOLD)
                    {
                        r.x = v.Right;
                    }

                    if (Math.Abs(r.y - v.Top) < SNAPTHRESHOLD)
                    {
                        int diff = r.y - v.Top;
                        r.y = v.Top;
                        r.cy += diff;
                    }

                    if (Math.Abs(r.y - v.Bottom) < SNAPTHRESHOLD)
                    {
                        int diff = r.y - v.Bottom;
                        r.y = v.Bottom;
                        r.cy += diff;
                    }

                    if (Math.Abs(r.y + r.cy - v.Top) < SNAPTHRESHOLD)
                    {
                        r.cy = v.Top-r.y;
                    }

                    if (Math.Abs(r.y + r.cy - v.Bottom) < SNAPTHRESHOLD)
                    {
                        r.cy = v.Bottom - r.y;
                    }

                }
            }
        }