private Point CalculateLocation(Control userCtrl, ControlPosition position, Point?location, Control owner) { var pt = Point.Empty; var ownerPos = Point.Empty; switch (position) { case ControlPosition.Owner: System.Diagnostics.Debug.Assert(owner != null, "Missing Owner"); if (userCtrl is Form) { pt = owner.PointToScreen(Point.Empty); } else { pt = owner.Location; } pt.Y += owner.Height; ownerPos = _owner.PointToScreen(Point.Empty); if (pt.X + userCtrl.Width > ownerPos.X + _owner.Width) { pt.X = ownerPos.X + _owner.Width - userCtrl.Width; } return(pt); case ControlPosition.Center: ownerPos = _owner.PointToScreen(Point.Empty); ownerPos.X += (owner.Width - userCtrl.Width) / 2; ownerPos.Y += (owner.Height - userCtrl.Height) / 2; if (ownerPos.X < 0) { ownerPos.X = 0; } if (ownerPos.Y < 0) { ownerPos.Y = 0; } return(ownerPos); case ControlPosition.Manual: System.Diagnostics.Debug.Assert(location != null, "Location is null"); return((Point)location); default: return((Point)location); } }