/// <summary> /// Use the setting from the Positioning to display the tooltip /// </summary> /// <param name="target"></param> /// <param name="controlMousePosition"></param> public void ShowRelativeTo(ViewBase target, Point controlMousePosition) { PopupPositionValues position; if (_contentValues is ToolTipValues toolTipValues) { position = toolTipValues.ToolTipPosition; } else { position = new PopupPositionValues(); } Point currentCursorHotSpot = CommonHelper.CaptureCursor(); Rectangle positionPlacementRectangle = position.PlacementRectangle; switch (position.PlacementMode) { case PlacementMode.Absolute: case PlacementMode.AbsolutePoint: // The screen, or PlacementRectangle if it is set. // So do nothing ! break; case PlacementMode.Mouse: case PlacementMode.MousePoint: // The bounds of the mouse pointer. PlacementRectangle is ignored positionPlacementRectangle = new Rectangle(controlMousePosition.X, controlMousePosition.Y, currentCursorHotSpot.X + 2, currentCursorHotSpot.Y + 2); break; default: // The screen, or PlacementRectangle if it is set. The PlacementRectangle is relative to the screen. if (positionPlacementRectangle.IsEmpty) { // PlacementTarget or parent. positionPlacementRectangle = position.PlacementTarget?.ClientRectangle ?? target.ClientRectangle; positionPlacementRectangle = (position.PlacementTarget?.OwningControl ?? target.OwningControl).RectangleToScreen(positionPlacementRectangle); } else { positionPlacementRectangle = Screen.GetWorkingArea(controlMousePosition); } break; } // Get the size the popup would like to be Size popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty); Point popupLocation; switch (position.PlacementMode) { case PlacementMode.Absolute: case PlacementMode.AbsolutePoint: case PlacementMode.MousePoint: case PlacementMode.Relative: case PlacementMode.RelativePoint: // The top-left corner of the target area. The top-left corner of the Popup. popupLocation = positionPlacementRectangle.Location; if (positionPlacementRectangle.IntersectsWith(new Rectangle(controlMousePosition, (Size)currentCursorHotSpot))) { // TODO: SKC: Should really get the HotSpot from the Icon and use that ! popupLocation.X = controlMousePosition.X + 4; // Still might "Bounce back" due to offscreen location } break; case PlacementMode.Bottom: case PlacementMode.Mouse: // The bottom-left corner of the target area. The top-left corner of the Popup. popupLocation = new Point(positionPlacementRectangle.Left, positionPlacementRectangle.Bottom); break; case PlacementMode.Center: // The center of the target area. The center of the Popup. popupLocation = positionPlacementRectangle.Location; popupLocation.Offset(popupSize.Width / 2, -popupSize.Height / 2); if (positionPlacementRectangle.IntersectsWith(new Rectangle(controlMousePosition, (Size)currentCursorHotSpot))) { // TODO: SKC: Should really get the HotSpot from the Icon and use that ! popupLocation.X = controlMousePosition.X + 4; // Still might "Bounce back" due to offscreen location } break; case PlacementMode.Left: // The top-left corner of the target area. The top-right corner of the Popup. popupLocation = new Point(positionPlacementRectangle.Left - popupSize.Width, positionPlacementRectangle.Top); break; case PlacementMode.Right: // The top-right corner of the target area. The top-left corner of the Popup. popupLocation = new Point(positionPlacementRectangle.Right, positionPlacementRectangle.Top); break; case PlacementMode.Top: // The top-left corner of the target area. The bottom-left corner of the Popup. popupLocation = new Point(positionPlacementRectangle.Left, positionPlacementRectangle.Top - popupSize.Height); break; default: throw new ArgumentOutOfRangeException(); } // Show it now! Show(popupLocation, popupSize); }
/// <summary> /// </summary> /// <param name="needPaint"></param> public ToolTipValues(NeedPaintHandler needPaint) : base(needPaint) { ResetToolTipStyle(); ToolTipPosition = new PopupPositionValues(); }