// The static methods that actually do the work public static void LocateInside(Control ctrl, Control c, Btn.Horizontal h, Btn.Vertical v, int d) { int x = 0; int y = 0; if (h == Horizontal.Left) { x = d; } if (h == Horizontal.CopyLeft) { x = c.Location.X; } if (h == Horizontal.Center) { x = (c.ClientSize.Width - ctrl.Size.Width) / 2; } if (h == Horizontal.CopyRight) { x = c.Location.X + c.Size.Width - ctrl.Size.Width; } if (h == Horizontal.Right) { x = c.ClientSize.Width - ctrl.Size.Width - d; } if (v == Vertical.Top) { y = d; } if (v == Vertical.CopyTop) { y = c.Location.Y; } if (v == Vertical.Middle) { y = (c.ClientSize.Height - ctrl.Size.Height) / 2; } if (v == Vertical.CopyBottom) { y = c.Location.Y + c.ClientSize.Height - ctrl.Size.Height; } if (v == Vertical.Bottom) { y = c.ClientSize.Height - ctrl.Size.Height - d; } ctrl.Location = new Point(x, y); }
/// <summary> /// Locate this control adjacent to the other control in a specific way /// </summary> /// <param name="c">The other control</param> /// <param name="h">The horizontal placement</param> /// <param name="v">The vertical placement</param> /// <param name="distance">The margin</param> public void LocateFrom(Control c, Btn.Horizontal h = Btn.Horizontal.CopyLeft, Btn.Vertical v = Btn.Vertical.CopyTop, int d = Btn.distance) { Btn.LocateFrom(this, c, h, v, d); }
/// <summary> /// Locate this control inside its parent in a specific way /// </summary> /// <param name="c">It's parent</param> /// <param name="h">The horizontal placement</param> /// <param name="v">The vertical placement</param> /// <param name="distance">The margin</param> public void LocateInside(Control c, Btn.Horizontal h = Btn.Horizontal.Left, Btn.Vertical v = Btn.Vertical.Top, int d = Btn.distance) { Btn.LocateInside(this, c, h, v, d); }