Esempio n. 1
0
        private void Move(Point p)
        {
            p = originalForm.PointToScreen(p);
            Screen activeScr = Screen.FromPoint(p);	// get the screen from the point !!

            if (!activeScr.WorkingArea.Contains(p))
            {
                p.X = NormalizeInside(p.X, activeScr.WorkingArea.Left, activeScr.WorkingArea.Right);
                p.Y = NormalizeInside(p.Y, activeScr.WorkingArea.Top, activeScr.WorkingArea.Bottom);
            }

            p.Offset(-offsetPoint.X, -offsetPoint.Y);

            // p is the exact location of the frame - so we can play with it
            // to detect the new position acording to different bounds
            formRect.Location = p;	// this is the new positon of the form

            formOffsetPoint.X = stickGap + 1;	// (more than) maximum gaps
            formOffsetPoint.Y = stickGap + 1;

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

            // Now try to snap to other windows
            if (stickToOther)
            {
                foreach (IFormAdapter sw in GlobalStickyWindows)
                {
                    if (sw != this.originalForm)
                    {
                        int beforeX = formOffsetPoint.X;
                        int beforeY = formOffsetPoint.Y;
                        if (!moveStuck || (moveStuck && !stuckWindows.ContainsKey(sw)))
                        {
                            Move_Stick(sw.Bounds, true);
                        }
                        if (moveStuck &&
                            (beforeX != formOffsetPoint.X || beforeY != formOffsetPoint.Y) &&
                            !stuckWindows.ContainsKey(sw))
                        {
                            if (formOffsetPoint.X == stickGap + 1)
                                formOffsetPoint.X = 0;
                            if (formOffsetPoint.Y == stickGap + 1)
                                formOffsetPoint.Y = 0;
                            stuckWindows[sw] = new StuckWindow { Offset = new Point { X = sw.Bounds.X - formRect.X - formOffsetPoint.X, Y = sw.Bounds.Y - formRect.Y - formOffsetPoint.Y } };
                            sw.StickyWindow.IsStuck = true;
                        }
                    }
                }
            }

            if (formOffsetPoint.X == stickGap + 1)
                formOffsetPoint.X = 0;
            if (formOffsetPoint.Y == stickGap + 1)
                formOffsetPoint.Y = 0;

            formRect.Offset(formOffsetPoint);

            originalForm.Bounds = formRect;

            if (moveStuck)
            {
                foreach (var window in stuckWindows.Keys)
                {
                    var stuckWindow = stuckWindows[window];
                    var offset = stuckWindow.Offset;
                    var rec = window.Bounds;
                    rec.X = originalForm.Bounds.X + offset.X;
                    rec.Y = originalForm.Bounds.Y + offset.Y;
                    window.Bounds = rec;
                }
            }
            if (isStuck)
            {
                foreach (var sw in GlobalStickyWindows)
                {
                    if (sw != this.originalForm && IsStuckTo(sw, true) != StickDir.None)
                    {
                        sw.StickyWindow.UnstickMe(this.originalForm);
                    }
                }
                isStuck = false;
            }            
        }
Esempio n. 2
0
        private void Move(Point p)
        {
            p = originalForm.PointToScreen(p);
            Screen activeScr = Screen.FromPoint(p);     // get the screen from the point !!

            if (!activeScr.WorkingArea.Contains(p))
            {
                p.X = NormalizeInside(p.X, activeScr.WorkingArea.Left, activeScr.WorkingArea.Right);
                p.Y = NormalizeInside(p.Y, activeScr.WorkingArea.Top, activeScr.WorkingArea.Bottom);
            }

            p.Offset(-offsetPoint.X, -offsetPoint.Y);

            // p is the exact location of the frame - so we can play with it
            // to detect the new position acording to different bounds
            formRect.Location = p;            // this is the new positon of the form

            formOffsetPoint.X = stickGap + 1; // (more than) maximum gaps
            formOffsetPoint.Y = stickGap + 1;

            if (stickToScreen)
            {
                Move_Stick(activeScr.WorkingArea, false);
            }

            // Now try to snap to other windows
            if (stickToOther)
            {
                foreach (IFormAdapter sw in GlobalStickyWindows)
                {
                    if (sw != this.originalForm)
                    {
                        int beforeX = formOffsetPoint.X;
                        int beforeY = formOffsetPoint.Y;
                        if (!moveStuck || (moveStuck && !stuckWindows.ContainsKey(sw)))
                        {
                            Move_Stick(sw.Bounds, true);
                        }
                        if (moveStuck &&
                            (beforeX != formOffsetPoint.X || beforeY != formOffsetPoint.Y) &&
                            !stuckWindows.ContainsKey(sw))
                        {
                            if (formOffsetPoint.X == stickGap + 1)
                            {
                                formOffsetPoint.X = 0;
                            }
                            if (formOffsetPoint.Y == stickGap + 1)
                            {
                                formOffsetPoint.Y = 0;
                            }
                            stuckWindows[sw] = new StuckWindow {
                                Offset = new Point {
                                    X = sw.Bounds.X - formRect.X - formOffsetPoint.X, Y = sw.Bounds.Y - formRect.Y - formOffsetPoint.Y
                                }
                            };
                            sw.StickyWindow.IsStuck = true;
                        }
                    }
                }
            }

            if (formOffsetPoint.X == stickGap + 1)
            {
                formOffsetPoint.X = 0;
            }
            if (formOffsetPoint.Y == stickGap + 1)
            {
                formOffsetPoint.Y = 0;
            }

            formRect.Offset(formOffsetPoint);

            originalForm.Bounds = formRect;

            if (moveStuck)
            {
                foreach (var window in stuckWindows.Keys)
                {
                    var stuckWindow = stuckWindows[window];
                    var offset      = stuckWindow.Offset;
                    var rec         = window.Bounds;
                    rec.X         = originalForm.Bounds.X + offset.X;
                    rec.Y         = originalForm.Bounds.Y + offset.Y;
                    window.Bounds = rec;
                }
            }
            if (isStuck)
            {
                foreach (var sw in GlobalStickyWindows)
                {
                    if (sw != this.originalForm && IsStuckTo(sw, true) != StickDir.None)
                    {
                        sw.StickyWindow.UnstickMe(this.originalForm);
                    }
                }
                isStuck = false;
            }
        }