public GetPreferredSize ( IRenderer renderer, |
||
renderer | IRenderer | Renderer provider. |
proposedSize | The custom-sized area for a control. | |
return |
/// <summary> /// Show the tooltip popup relative to the provided screen position. /// </summary> /// <param name="screenRect">Screen position to display relative to.</param> public void ShowCalculatingSize(Rectangle screenRect) { // Get the size the popup would like to be Size popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty); // Find the screen position the popup will be relative to screenRect = new Rectangle(screenRect.X, screenRect.Y - VERT_OFFSET, screenRect.Width, screenRect.Height + (VERT_OFFSET * 2)); // Show it now! Show(screenRect, popupSize); }
/// <summary> /// Show the tooltip popup relative to the provided screen position. /// </summary> /// <param name="controlMousePosition">Screen point of cursor.</param> public void ShowCalculatingSize(Point controlMousePosition) { // Get the size the popup would like to be Size popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty); // Find the screen position the popup will be relative to Point currentCursorHotSpot = CommonHelper.CaptureCursor(); controlMousePosition.Offset(currentCursorHotSpot.X + 2, currentCursorHotSpot.Y + 2); // Show it now! Show(controlMousePosition, popupSize); }
/// <summary> /// Show the tooltip popup relative to the provided screen position. /// </summary> /// <param name="screenPt">Screen point of cursor.</param> public void ShowCalculatingSize(Point screenPt) { // Get the size the popup would like to be Size popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty); // Find the screen position the popup will be relative to Rectangle screenRect = new Rectangle(screenPt.X + HORZ_OFFSET - (popupSize.Width / 2), screenPt.Y - VERT_OFFSET, 1, VERT_OFFSET * 2); // Show it now! Show(screenRect, popupSize); }
/// <summary> /// Get the preferred size of the control based on a proposed size. /// </summary> /// <param name="proposedSize">Starting size proposed by the caller.</param> /// <returns>Calculated preferred size.</returns> public override Size GetPreferredSize(Size proposedSize) { // Do we have a manager to ask for a preferred size? if (ViewManager != null) { // Ask the view to peform a layout Size retSize = ViewManager.GetPreferredSize(Renderer, proposedSize); // Apply the maximum sizing if (MaximumSize.Width > 0) { retSize.Width = Math.Min(MaximumSize.Width, retSize.Width); } if (MaximumSize.Height > 0) { retSize.Height = Math.Min(MaximumSize.Height, retSize.Width); } // Apply the minimum sizing if (MinimumSize.Width > 0) { retSize.Width = Math.Max(MinimumSize.Width, retSize.Width); } if (MinimumSize.Height > 0) { retSize.Height = Math.Max(MinimumSize.Height, retSize.Height); } return(retSize); } else { // Fall back on default control processing return(base.GetPreferredSize(proposedSize)); } }
/// <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); }