public static Point GetNextStackedFormLocation(CreateParams cp) { if (cp.control == null) { return(Point.Empty); } MdiClient parent = cp.control.Parent as MdiClient; if (parent != null) { return(parent.GetNextStackedFormLocation(cp)); } int X = cp.X; int Y = cp.Y; Point previous, next; Rectangle within; previous = Hwnd.previous_main_startup_location; within = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; if (previous.X == int.MinValue || previous.Y == int.MinValue) { next = Point.Empty; } else { next = new Point(previous.X + 22, previous.Y + 22); } if (!within.Contains(next.X * 3, next.Y * 3)) { next = Point.Empty; } if (next == Point.Empty && cp.Parent == IntPtr.Zero) { next = new Point(22, 22); } Hwnd.previous_main_startup_location = next; return(next); }