Exemplo n.º 1
0
        Point GetDropSpot(Window w, Rectangle target)
        {
            AccessibleObject acc = w.AccessibleObject;
            Rectangle source = acc.Bounds;
            source.Inflate(20, 20); // add extra margin
            if (source.Contains(target)) {
                // Source window is completely occluding the target window, so we need to move it!
                Point from = new Point(source.Left + (source.Width/2), source.Top + 5);
                int amount = target.Left - source.Left + 100;
                Point end = new Point(from.X + amount, from.Y);
                // Move window to the right.
                Mouse.MouseDown(from, MouseButtons.Left);
                Mouse.MouseDragDrop(from, end, 5, MouseButtons.Left);

                source = acc.Bounds;
            }
            if (source.Left > target.Left) {
                // pick a spot along the left margin
                return new Point((target.Left + source.Left) / 2, (target.Top + target.Bottom) / 2);
            } else if (source.Right < target.Right) {
                // pick a spot along the right margin
                return new Point((target.Right + source.Right) / 2, (target.Top + target.Bottom) / 2);
            } else if (source.Top > target.Top) {
                // top margin
                return new Point((target.Right + target.Left) / 2, (source.Top + target.Top) / 2);
            } else if (source.Bottom < target.Bottom) {
                // bottom margin
                return new Point((target.Right + target.Left) / 2, (source.Bottom + target.Bottom) / 2);
            }

            // Then MOVE the window so it's not in the way!
            w.SetWindowPosition(target.Right, source.Top);
            Sleep(1000);
            source = acc.Bounds;
            return new Point((target.Left + source.Left) / 2, (target.Top + target.Bottom) / 2);
        }