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